#import "progressBar.h"
@interface progressBar ()
@property (nonatomic, weak) IBOutlet UISlider *progressSlider;
@property (nonatomic, weak) IBOutlet UILabel *showValue;
@end
@implementation progressBar
- (void)awakeFromNib
{
[self.progressSlider addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventValueChanged];
self.progressSlider.value = 0;
}
- (void)valueChange:(UISlider *)slider
{
self.showValue.text = [NSString stringWithFormat:@"%.2f%%",slider.value * 100.0];
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
// 描述路径
CGPoint center = CGPointMake(self.bounds.size.width *0.5, self.bounds.size.height * 0.5);
CGFloat radius = self.bounds.size.width * 0.5 - 10;
CGFloat startA = 0;
CGFloat endA = self.progressSlider.value * M_PI * 2;
NSLog(@"endA = %f",endA);
NSLog(@"self.progressSlider.value = %f",self.progressSlider.value);
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES];
[path stroke];
}
@end