本文实例为大家分享了swift圆环进度提示效果的实现代码,供大家参考,具体内容如下
效果图:
实现代码:
/ // viewcontroller.swift // pureswiftauto // // created by 王木木 on 16/5/17. // 凯发网娱乐官网下载 copyright © 2016年 王木木. all rights reserved. // import uikit class viewcontroller: uiviewcontroller { let cireview = cireview.newautolayoutview() override func viewdidload() { super.viewdidload() // do any additional setup after loading the view, typically from a nib. creatcire() } func creatcire(){ self.view.addsubview(cireview) self.cireview.value = 2 self.cireview.maximumvalue = 100 self.cireview.backgroundcolor = uicolor.yellowcolor() self.cireview.frame = cgrectmake(100, 100, 100, 100) wangmumu() } func wangmumu(){ self.cireview.value = 2 if self.cireview.value == 90 {return} self.performselector("wangmumu", withobject: self, afterdelay: 0.2) } } class cireview: uiview{ var value: cgfloat = 0 { didset { self.setneedsdisplay() } } var maximumvalue: cgfloat = 0 { didset { self.setneedsdisplay() } } override init(frame: cgrect) { super.init(frame: frame) self.opaque = false } override func drawrect(rect: cgrect) { super.drawrect(rect) //线宽度 let linewidth: cgfloat = 10.0 //半径 let radius = cgrectgetwidth(rect) / 2.0 - linewidth //中心点x let centerx = cgrectgetmidx(rect) //中心点y let centery = cgrectgetmidy(rect) //弧度起点 let startangle = cgfloat(-90 * m_pi / 180) //弧度终点 let endangle = cgfloat(((self.value / self.maximumvalue) * 360 - 90) ) * cgfloat(m_pi) / 180 //创建一个画布 let context = uigraphicsgetcurrentcontext() //画笔颜色 cgcontextsetstrokecolorwithcolor(context, uicolor.bluecolor().cgcolor) //画笔宽度 cgcontextsetlinewidth(context, linewidth) //(1)画布 (2)中心点x(3)中心点y(4)圆弧起点(5)圆弧结束点(6) 0顺时针 1逆时针 cgcontextaddarc(context, centerx, centery, radius, startangle, endangle, 0) //绘制路径 cgcontextstrokepath(context) //画笔颜色 cgcontextsetstrokecolorwithcolor(context, uicolor.darkgraycolor().cgcolor) //(1)画布 (2)中心点x(3)中心点y(4)圆弧起点(5)圆弧结束点(6) 0顺时针 1逆时针 cgcontextaddarc(context, centerx, centery, radius, startangle, endangle, 1) //绘制路径 cgcontextstrokepath(context) } required init?(coder adecoder: nscoder) { fatalerror("init(coder:) has not been implemented") } }
以上就是本文的全部内容,希望对大家的学习有所帮助。