Last active
June 11, 2020 08:47
-
-
Save alexnikol/24cc009f414532e8559fb60e5e8c23a6 to your computer and use it in GitHub Desktop.
Draw Segment Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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