Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.45 KB | None | 0 0
  1. class ViewController: UIViewController {
  2.    
  3.     @IBOutlet weak var chartView: UIView!
  4.    
  5.     override func viewDidAppear(_ animated: Bool) {
  6.         super.viewDidAppear(animated)
  7.         createCircularPath()
  8.     }
  9.    
  10.     fileprivate func createCircularPath() {
  11.        
  12.         let trakLayer = CAShapeLayer()
  13.         let progress = CAShapeLayer()
  14.        
  15.         let frame = chartView.frame
  16.         chartView.layer.cornerRadius = chartView.frame.height * 0.5
  17.         chartView.backgroundColor = .clear
  18.        
  19.         let center = CGPoint(x: frame.width * 0.5, y: frame.height * 0.5)
  20.         let radius = (frame.width - 1.5) / 2
  21.         let startAngle = -0.5 * Double.pi
  22.         let endAngle = 1.5 * Double.pi
  23.         let bezie = UIBezierPath(arcCenter: center, radius: radius, startAngle: CGFloat(startAngle), endAngle: CGFloat(endAngle), clockwise: true)
  24.        
  25.         trakLayer.path = bezie.cgPath
  26.         trakLayer.fillColor = UIColor.clear.cgColor
  27.         trakLayer.strokeColor = UIColor.red.withAlphaComponent(0.3).cgColor
  28.         trakLayer.lineWidth = 10
  29.         trakLayer.strokeEnd = 1.0
  30.        
  31.         progress.path = bezie.cgPath
  32.         progress.fillColor = UIColor.clear.cgColor
  33.         progress.strokeColor = UIColor.red.cgColor
  34.         progress.lineWidth = 10
  35.         progress.strokeEnd = 0.50
  36.        
  37.        
  38.         chartView.layer.addSublayer(trakLayer)
  39.         chartView.layer.addSublayer(progress)
  40.     }
  41.  
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement