import UIKit class progresscustom: UIView { override init(frame: CGRect) { super.init(frame: frame) self.backgroundColor = UIColor(white: 1, alpha: 0) } required init(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } private var _progressValue :CGFloat = 0 internal func getProgressVlue() ->CGFloat{ return _progressValue ; } internal func setProgressValue(value : CGFloat){ _progressValue = value ; setNeedsDisplay() ; } // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation.当子图需要表现在VIew上的时候,需要重写这个方法 override func drawRect(rect: CGRect) { // Drawing code var ctx = UIGraphicsGetCurrentContext() ; var r = rect.width/2 CGContextAddArc(ctx,r, r, r, 0, 3.1415926*2, 0) CGContextAddLineToPoint(ctx, r, r) CGContextSetRGBFillColor(ctx, 0.7, 0.7, 0.7, 1) CGContextFillPath(ctx) CGContextAddArc(ctx,r, r, r, 0, 3.1415926*2*_progressValue, 0) CGContextAddLineToPoint(ctx, r, r) CGContextSetRGBFillColor(ctx, 0, 0, 1, 1) CGContextFillPath(ctx) CGContextStrokePath(ctx) CGContextSetLineWidth(ctx, 5) }
原文:http://www.cnblogs.com/KyleRuan/p/4296135.html