Examples of this article for you to share the swift ring progress effect of the implementation code, for your reference, the specific content as follows
Effect Chart:
Implementation code:
////Viewcontroller.swift//Pureswiftauto////Created by Wang Mumu on 16/5/17. copyright©2016, the King of the Year wood.
All rights reserved. Import Uikit class Viewcontroller:uiviewcontroller {Let Cireview = Cireview.newautolayoutview () overr IDE Func viewdidload () {super.viewdidload ()//Do no additional setup after loading the view, typically from a n
Ib. Creatcire ()} func Creatcire () {Self.view.addSubview (cireview) Self.cireView.value = 2 self.cireview.m Aximumvalue = Self.cireView.backgroundColor = Uicolor.yellowcolor () self.cireView.frame = CGRectMake (100, 100, Wangmumu ()} func Wangmumu () {Self.cireView.value + = 2 if Self.cireView.value = = Self.performselector {return} ("Wangmumu", Withobject:self, afterdelay:0.2)}} class Cire view:uiview{var value:cgfloat = 0 {didset {self.setneedsdisplay ()}} var Maximumvalue:c
Gfloat = 0 { Didset {Self.setneedsdisplay ()}} override init (Frame:cgrect) {super.init (frame:frame) Self.opaque = f Alse} override func DrawRect (rect:cgrect) {super.drawrect (rect)//Line width let LINEWIDTH:CGFL Oat = 10.0//radius Let radius = cgrectgetwidth (rect)/2.0-linewidth//center point x Let CenterX = Cgrectgetmidx (rec
T)//center point y let centery = cgrectgetmidy (rect)//radian start let startangle = CGFloat ( -90 * m_pi/180)//radians end point Let Endangle = CGFloat ((self.value/self.maximumvalue) * 360-90)) * CGFloat (M_PI)/180//Create a canvas let context = Uigraphicsgetcurrentcontext ()//Brush color Cgcontextsetstrokecolorwithcolor (context, Uicolor.bluecolor ( ). Cgcolor)//Brush width cgcontextsetlinewidth (context, linewidth)//(1) Canvas (2) center point X (3) center point Y (4) Arc start point (5) Arc end point (6) 0 Clockwise 1 Counterclockwise cgcontextaddarc (context, CenterX, centery, radius, startangle, Endangle, 0)//Draw path cgcontexts
Trokepath (context)
Brush color Cgcontextsetstrokecolorwithcolor (context, Uicolor.darkgraycolor (). Cgcolor)//(1) Canvas (2) center point X (3) center point Y (4) Arc beginning (5) Arc end point (6) 0 clockwise 1 counterclockwise cgcontextaddarc (context, CenterX, CenterY, Radiu S, StartAngle, Endangle, 1//Draw path Cgcontextstrokepath (context)} required init? (Coder Adecoder:nscoder) {FatalError ("init (coder:) has not been implemented")}}
The above is the entire content of this article, I hope to help you learn.