Skip to content

Instantly share code, notes, and snippets.

@alexnikol
Last active June 11, 2020 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexnikol/24cc009f414532e8559fb60e5e8c23a6 to your computer and use it in GitHub Desktop.
Save alexnikol/24cc009f414532e8559fb60e5e8c23a6 to your computer and use it in GitHub Desktop.
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