Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ViewController: UIViewController {
- @IBOutlet weak var chartView: UIView!
- override func viewDidAppear(_ animated: Bool) {
- super.viewDidAppear(animated)
- createCircularPath()
- }
- fileprivate func createCircularPath() {
- let trakLayer = CAShapeLayer()
- let progress = CAShapeLayer()
- let frame = chartView.frame
- chartView.layer.cornerRadius = chartView.frame.height * 0.5
- chartView.backgroundColor = .clear
- let center = CGPoint(x: frame.width * 0.5, y: frame.height * 0.5)
- let radius = (frame.width - 1.5) / 2
- let startAngle = -0.5 * Double.pi
- let endAngle = 1.5 * Double.pi
- let bezie = UIBezierPath(arcCenter: center, radius: radius, startAngle: CGFloat(startAngle), endAngle: CGFloat(endAngle), clockwise: true)
- trakLayer.path = bezie.cgPath
- trakLayer.fillColor = UIColor.clear.cgColor
- trakLayer.strokeColor = UIColor.red.withAlphaComponent(0.3).cgColor
- trakLayer.lineWidth = 10
- trakLayer.strokeEnd = 1.0
- progress.path = bezie.cgPath
- progress.fillColor = UIColor.clear.cgColor
- progress.strokeColor = UIColor.red.cgColor
- progress.lineWidth = 10
- progress.strokeEnd = 0.50
- chartView.layer.addSublayer(trakLayer)
- chartView.layer.addSublayer(progress)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement