ios学习随笔四
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) }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。