Import UIKit
Class Xzcircleview:uiview {
Let Backgroundlayer = Cashapelayer.init ()///Background white fine curve
Let Progresslayer = Cashapelayer.init ()///progress is really a numerical curve
var Endvale = 0.00
var progresscolor = UIColor.white.cgColor
var backColor = "FFFFFF". Touicolorwithalpha (0.2). Cgcolor
only override Draw () If you perform custom drawing.
An empty implementation adversely affects performance during animation.
Override Func Draw (_ Rect:cgrect) {
Drawing Code
Self.inittheview (Rect)
}
Func Inittheview (_ Rect:cgrect) {
Set the percentage animation display
Set a white background line
Self.backGroundLayer.frame = rect
Self.backGroundLayer.fillColor = UIColor.clear.cgColor
Self.backGroundLayer.lineWidth = 1
Let Backpath = Uibezierpath.init (ArcCenter:CGPoint.init (X:self.p_centerx, Y:self.p_centery), Radius: self.frame.size.width/2.00, Startangle:cgfloat (-DOUBLE.PI * 7.0/6.0), endangle:cgfloat (double.pi/6.0), clockwise: True
Self.backGroundLayer.path = Backpath.cgpath
Self.backGroundLayer.strokeStart = 0
Self.backGroundLayer.strokeEnd = 1
Self.backGroundLayer.strokeColor = BackColor
Self.layer.addSublayer (Self.backgroundlayer)
Self.backGroundLayer.fillColor = UIColor.clear.cgColor
Self.backGroundLayer.lineWidth = 1
Set the real progress curve
Self.progressLayer.frame = rect
Self.progressLayer.fillColor = UIColor.clear.cgColor
Self.progressLayer.lineWidth = 12
Self.progressLayer.lineCap = Kcalinecapround
Let Progresspath = Uibezierpath.init (ArcCenter:CGPoint.init (X:self.p_centerx, Y:self.p_centery), Radius: self.frame.size.width/2.00, Startangle:cgfloat (-DOUBLE.PI * 7.0/6.0), endangle:cgfloat (EndVale), clockwise:true)
Self.progressLayer.path = Progresspath.cgpath
Self.progressLayer.strokeStart = 0
Self.progressLayer.strokeEnd = 1
Self.progressLayer.strokeColor = Progresscolor
Self.layer.addSublayer (Self.progresslayer)
Add animations
Let pathanimation = Cabasicanimation.init (keypath: "Strokeend")
Pathanimation.duration = 0.5
Pathanimation.fromvalue = 0
Pathanimation.tovalue = 1
Pathanimation.timingfunction = Camediatimingfunction.init (name:kcamediatimingfunctioneaseout)
Self.progressLayer.add (Pathanimation, Forkey: "Strokeend")
}
}
IOS percent Ring curve swift4.0 implementation