Skip to content

Commit dc82201

Browse files
committed
Corner radius for progress view
We want to customize corner radius for progress view. The corner radius for progress view is dependent on progressViewThickness, it means we can not customize it without changing progressViewThickness.
1 parent 5665de3 commit dc82201

File tree

5 files changed

+65
-20
lines changed

5 files changed

+65
-20
lines changed

Classes/ProgressViews/M13ProgressViewBar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ typedef enum {
3535
@property (nonatomic, assign) M13ProgressViewBarProgressDirection progressDirection;
3636
/**The thickness of the progress bar.*/
3737
@property (nonatomic, assign) CGFloat progressBarThickness;
38+
/**The corner radius of the progress bar.*/
39+
@property (nonatomic, assign) CGFloat progressBarCornerRadius;
3840
/**@name Actions*/
3941
/**The color the bar changes to for the success action.*/
4042
@property (nonatomic, retain) UIColor *successColor;

Classes/ProgressViews/M13ProgressViewBar.m

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ - (void)setup
7676
self.animationDuration = .3;
7777
_progressDirection = M13ProgressViewBarProgressDirectionLeftToRight;
7878
_progressBarThickness = 2;
79+
_progressBarCornerRadius = _progressBarThickness / 2.0;
7980
_percentagePosition = M13ProgressViewBarPercentagePositionRight;
8081
_showPercentage = YES;
8182

@@ -92,7 +93,7 @@ - (void)setup
9293
//Progress View
9394
_progressBar = [[UIView alloc] init];
9495
_progressBar.backgroundColor = self.secondaryColor;
95-
_progressBar.layer.cornerRadius = _progressBarThickness / 2.0;
96+
_progressBar.layer.cornerRadius = _progressBarCornerRadius;
9697
_progressBar.clipsToBounds = YES;
9798
[self addSubview:_progressBar];
9899

@@ -115,7 +116,7 @@ - (void)setup
115116
//IndeterminateLayer
116117
_indeterminateLayer = [CALayer layer];
117118
_indeterminateLayer.backgroundColor = self.primaryColor.CGColor;
118-
_indeterminateLayer.cornerRadius = _progressBarThickness / 2.0;
119+
_indeterminateLayer.cornerRadius = _progressBarCornerRadius;
119120
_indeterminateLayer.opacity = 0;
120121
[_progressBar.layer addSublayer:_indeterminateLayer];
121122

@@ -185,6 +186,19 @@ - (void)setProgressBarThickness:(CGFloat)progressBarThickness
185186
[self invalidateIntrinsicContentSize];
186187
}
187188

189+
- (void)setProgressBarCornerRadius:(CGFloat)progressBarCornerRadius
190+
{
191+
_progressBarCornerRadius = progressBarCornerRadius;
192+
193+
// Update the layer size
194+
[self setNeedsDisplay];
195+
196+
// Update corner radius for layers
197+
_progressBar.layer.cornerRadius = _progressBarCornerRadius;
198+
_indeterminateLayer.cornerRadius = _progressBarCornerRadius;
199+
[self invalidateIntrinsicContentSize];
200+
}
201+
188202
#pragma mark Actions
189203

190204
- (void)setProgress:(CGFloat)progress animated:(BOOL)animated

M13ProgressSuite/BarViewController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
@property (nonatomic, retain) IBOutlet UIButton *animateButton;
2424
@property (nonatomic, retain) IBOutlet UISegmentedControl *iconControl;
2525
@property (nonatomic, retain) IBOutlet UISwitch *indeterminateSwitch;
26+
@property (nonatomic, retain) IBOutlet UISwitch *cornerRadiusSwitch;
2627
@property (nonatomic, retain) IBOutlet UISwitch *showPercentageSwitch;
2728
@property (nonatomic, retain) IBOutlet UISegmentedControl *positionControl;
2829
@property (nonatomic, retain) IBOutlet UISegmentedControl *directionControl;
@@ -31,6 +32,7 @@
3132
- (IBAction)progressChanged:(id)sender;
3233
- (IBAction)iconChanged:(id)sender;
3334
- (IBAction)indeterminateChanged:(id)sender;
35+
- (IBAction)cornerRadiusChanged:(id)sender;
3436
- (IBAction)showPercentage:(id)sender;
3537
- (IBAction)percentagePositionChangeed:(id)sender;
3638
- (IBAction)directioChanged:(id)sender;

M13ProgressSuite/BarViewController.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ - (void)viewDidLoad
3838
//Set the percentage position
3939
_progressViewVertical.percentagePosition = M13ProgressViewBarPercentagePositionTop;
4040
_progressViewHorizontal.percentagePosition = M13ProgressViewBarPercentagePositionTop;
41+
42+
// Remove corner radius
43+
_progressViewVertical.progressBarCornerRadius = 0.0;
44+
_progressViewHorizontal.progressBarCornerRadius = 0.0;
4145
}
4246

4347
- (void)didReceiveMemoryWarning
@@ -92,6 +96,12 @@ - (void)indeterminateChanged:(id)sender
9296
[_progressViewVertical setIndeterminate:_indeterminateSwitch.on];
9397
}
9498

99+
- (IBAction)cornerRadiusChanged:(id)sender
100+
{
101+
[_progressViewHorizontal setProgressBarCornerRadius:_cornerRadiusSwitch.on ? _progressViewHorizontal.progressBarThickness / 2.0 : 0.0];
102+
[_progressViewVertical setProgressBarCornerRadius:_cornerRadiusSwitch.on ? _progressViewVertical.progressBarThickness / 2.0 : 0.0];
103+
}
104+
95105
- (void)animateProgress:(id)sender
96106
{
97107
//Disable other controls

0 commit comments

Comments
 (0)