Swift implements custom ring progress hint effect _swift

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.