swift完成自界說圓環進度提醒後果。本站提示廣大學習愛好者:(swift完成自界說圓環進度提醒後果)文章只能為提供參考,不一定能成為您想要的結果。以下是swift完成自界說圓環進度提醒後果正文
本文實例為年夜家分享了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")
}
}
以上就是本文的全體內容,願望對年夜家的進修有所贊助。