swift實(shí)現(xiàn)自定義圓環(huán)進(jìn)度提示效果
本文實(shí)例為大家分享了swift圓環(huán)進(jìn)度提示效果的實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
效果圖:
實(shí)現(xiàn)代碼:
/ // 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 //中心點(diǎn)x let centerX = CGRectGetMidX(rect) //中心點(diǎn)y let centerY = CGRectGetMidY(rect) //弧度起點(diǎn) let startAngle = CGFloat(-90 * M_PI / 180) //弧度終點(diǎn) let endAngle = CGFloat(((self.value / self.maximumValue) * 360 - 90) ) * CGFloat(M_PI) / 180 //創(chuàng)建一個(gè)畫布 let context = UIGraphicsGetCurrentContext() //畫筆顏色 CGContextSetStrokeColorWithColor(context, UIColor.blueColor().CGColor) //畫筆寬度 CGContextSetLineWidth(context, lineWidth) //(1)畫布 (2)中心點(diǎn)x(3)中心點(diǎn)y(4)圓弧起點(diǎn)(5)圓弧結(jié)束點(diǎn)(6) 0順時(shí)針 1逆時(shí)針 CGContextAddArc(context, centerX, centerY, radius, startAngle, endAngle, 0) //繪制路徑 CGContextStrokePath(context) //畫筆顏色 CGContextSetStrokeColorWithColor(context, UIColor.darkGrayColor().CGColor) //(1)畫布 (2)中心點(diǎn)x(3)中心點(diǎn)y(4)圓弧起點(diǎn)(5)圓弧結(jié)束點(diǎn)(6) 0順時(shí)針 1逆時(shí)針 CGContextAddArc(context, centerX, centerY, radius, startAngle, endAngle, 1) //繪制路徑 CGContextStrokePath(context) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。
相關(guān)文章
Swift中的條件判斷、循環(huán)、跳轉(zhuǎn)語(yǔ)句基礎(chǔ)學(xué)習(xí)筆記
if、for和while循環(huán)、switch等這些基本的程序流程控制語(yǔ)句基本上是每個(gè)編程語(yǔ)言的標(biāo)配,在入門環(huán)節(jié)中,這里對(duì)Swift中的條件判斷、循環(huán)、跳轉(zhuǎn)語(yǔ)句基礎(chǔ)學(xué)習(xí)筆記作了一個(gè)整理:2016-06-06Swift?并發(fā)修改Sendable?閉包實(shí)例詳解
這篇文章主要為大家介紹了Swift?并發(fā)修改Sendable?閉包實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10Objective-c代碼如何移植為Swift代碼 Objective-c代碼轉(zhuǎn)移到Swift過程介紹
這篇文章主要介紹了Objective-c代碼如何移植為Swift代碼,Objective-c代碼轉(zhuǎn)移到Swift過程介紹,需要的朋友可以參考下2014-07-07如何使用Swift來實(shí)現(xiàn)一個(gè)命令行工具的方法
這篇文章主要介紹了如何使用Swift來實(shí)現(xiàn)一個(gè)命令行工具,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05Swift中defer關(guān)鍵字推遲執(zhí)行示例詳解
這篇文章主要給大家介紹了關(guān)于Swift中defer關(guān)鍵字推遲執(zhí)行的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-03-03SwiftUI使用Paths和AnimatableData實(shí)現(xiàn)酷炫的顏色切換動(dòng)畫
這篇文章主要介紹了SwiftUI使用Paths和AnimatableData實(shí)現(xiàn)酷炫的顏色切換動(dòng)畫,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2020-05-05