自定义view
.h
@interface MSProgressView : UIView
@property (nonatomic, assign) CGFloat progress;
@end
.m
- (void)setProgress:(CGFloat)progress
{
_progress = progress;
self.label.text = [NSString stringWithFormat:@"%.2f%%",progress*100];
//调用重绘方法drawRect
[self setNeedsDisplay];
}
//视图第一次显示的时候自动调用调用
//[self setNeedsDisplay]手动调用重绘方法drawRect
- (void)drawRect:(CGRect)rect {
//绘制的中心点
CGPoint center = CGPointMake(rect.size.width*0.5, rect.size.height*0.5);
//绘制的半径
CGFloat radius = rect.size.width*0.5-5;
//开始绘制角度
CGFloat startAngle = -M_PI_2;
//结束的绘制角度
CGFloat endAngle = startAngle+M_PI*2*self.progress;
//贝赛尔曲线
//clockwise 是否顺时针 yes 顺时针 no 逆时针
UIBezierPath *path =
[UIBezierPath bezierPathWithArcCenter:center
radius:radius
startAngle:startAngle
endAngle:endAngle
clockwise:YES];
//设置线宽
[path setLineWidth:5];
//设置中间填充色
[[UIColor redColor] setFill];
//设置幅度线颜色
[[UIColor blackColor] setStroke];
//开始绘制
[path stroke];
//开始绘制填充
[path fill];
}
在控制器中 在storyboard中拖一个slider进度条
- (IBAction)download:(UISlider *)sender {
NSLog(@"progress = %f",sender.value);
self.progressView.progress = sender.value;
}