JLPieProgressView
仿新浪微博圖片加載進度條
實現(xiàn)代碼如下:
#import "JLPieProgressView.h"
@implementation JLPieProgressView
- (void)setProgressValue:(CGFloat)progressValue{
_progressValue = progressValue;
//重繪
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
//開始角度
CGFloat startAngle = -M_PI/2;
//結(jié)束角度
CGFloat endAngle = startAngle+M_PI*2*_progressValue;
CGFloat smallRadius = 10;//內(nèi)圓半徑
CGFloat bigRadius = smallRadius*2+2;//外圓半徑
CGContextRef ctx = UIGraphicsGetCurrentContext();
//畫外圓
[[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.8] set];
CGContextAddArc(ctx, rect.size.width/2, rect.size.height/2,bigRadius,0 , M_PI*2, 0);
CGContextStrokePath(ctx);
//畫內(nèi)圓
CGContextSetLineWidth(ctx, smallRadius*2);
CGContextAddArc(ctx, rect.size.width/2, rect.size.height/2, smallRadius,startAngle , endAngle, 0);
CGContextStrokePath(ctx);
}
下載點擊源代碼