Skip to content

Instantly share code, notes, and snippets.

@alexnikol
Last active Jun 11, 2020
Embed
What would you like to do?
Draw Segment Code
private func getSegment(startAngle: Radians,
endInAngle: Radians,
color: UIColor,
strokeEnd: CGFloat) -> CAShapeLayer {
let centre = CGPoint(x: bounds.width / 2, y: bounds.height / 2) //Center of drawing
let beizerPath = UIBezierPath(arcCenter: centre,
radius: bounds.height / 2 - settings.segmentWidth / 2, //Segment width
startAngle: startAngle, //Start angle in radians (0 for example)
endAngle: endInAngle, //End angle in radians (pi / 2 for example)
clockwise: true)
let segmentLayer = CAShapeLayer()
segmentLayer.path = beizerPath.cgPath //setting our path to new layer
segmentLayer.fillColor = UIColor.clear.cgColor //color of background
segmentLayer.strokeEnd = strokeEnd //end point of border 0 - 1 in percents (0 - border is hidden)
segmentLayer.lineWidth = settings.segmentWidth //Segment Width
segmentLayer.lineCap = settings.segmentBorderType //Type of line cap
segmentLayer.strokeColor = color.cgColor //Segment color
segmentLayer.strokeStart = 0.0 //start point of border 0 - 1 in percents (0 - border is hidden)
return segmentLayer
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment