ViewController.h 文件
#import "ViewController.h"
#import "ProgressView.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *labelView;
@property (weak, nonatomic) IBOutlet UISlider *slider;
@property (weak, nonatomic) IBOutlet ProgressView *progressView;
@end
@implementation ViewController
- (IBAction)sliderAction:(UISlider *)sender {
//設(shè)置label上的文字內(nèi)容
_labelView.text = [NSString stringWithFormat:@"%.2f%%",sender.value*100];
//傳值
_progressView.progress = sender.value;
}
ProgressView.h 文件
#import <UIKit/UIKit.h>
@interface ProgressView : UIView
//提供一個接受滑動條value值的屬性
@property(nonatomic,assign)CGFloat progress;
@end
ProgressView.m 文件
#import "ProgressView.h"
@implementation ProgressView
- (void)drawRect:(CGRect)rect {
//設(shè)置半徑
CGFloat radius = rect.size.width*0.5;
//圓心
CGPoint center = CGPointMake(radius, radius);
//終點
CGFloat endA = - M_PI_2 +_progress*M_PI*2;
//伊瑟爾路徑繪圖
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius-3 startAngle:-M_PI_2 endAngle:endA clockwise:YES];
//渲染
[path stroke];
}
//復(fù)寫set方法,作用:一旦progress的值改變,就重繪
-(void)setProgress:(CGFloat)progress{
_progress = progress;
//重繪,系統(tǒng)會先創(chuàng)建與view相關(guān)聯(lián)的上下文,然后再調(diào)用drawrect
[self setNeedsDisplay];
//注意:drawRect不能手動調(diào)用,因為圖形上下文我們自己創(chuàng)建不了,只能由系統(tǒng)幫我們創(chuàng)建,并且傳遞給我們
}
@end
storyboard中的布局

運行截圖(拖動滾動條,進(jìn)行畫圓)

效果圖