Skip to content

Commit

Permalink
Corner radius for progress view
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
trungp committed Jul 20, 2015
1 parent 5665de3 commit dc82201
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 20 deletions.
2 changes: 2 additions & 0 deletions Classes/ProgressViews/M13ProgressViewBar.h
Expand Up @@ -35,6 +35,8 @@ typedef enum {
@property (nonatomic, assign) M13ProgressViewBarProgressDirection progressDirection;
/**The thickness of the progress bar.*/
@property (nonatomic, assign) CGFloat progressBarThickness;
/**The corner radius of the progress bar.*/
@property (nonatomic, assign) CGFloat progressBarCornerRadius;
/**@name Actions*/
/**The color the bar changes to for the success action.*/
@property (nonatomic, retain) UIColor *successColor;
Expand Down
18 changes: 16 additions & 2 deletions Classes/ProgressViews/M13ProgressViewBar.m
Expand Up @@ -76,6 +76,7 @@ - (void)setup
self.animationDuration = .3;
_progressDirection = M13ProgressViewBarProgressDirectionLeftToRight;
_progressBarThickness = 2;
_progressBarCornerRadius = _progressBarThickness / 2.0;
_percentagePosition = M13ProgressViewBarPercentagePositionRight;
_showPercentage = YES;

Expand All @@ -92,7 +93,7 @@ - (void)setup
//Progress View
_progressBar = [[UIView alloc] init];
_progressBar.backgroundColor = self.secondaryColor;
_progressBar.layer.cornerRadius = _progressBarThickness / 2.0;
_progressBar.layer.cornerRadius = _progressBarCornerRadius;
_progressBar.clipsToBounds = YES;
[self addSubview:_progressBar];

Expand All @@ -115,7 +116,7 @@ - (void)setup
//IndeterminateLayer
_indeterminateLayer = [CALayer layer];
_indeterminateLayer.backgroundColor = self.primaryColor.CGColor;
_indeterminateLayer.cornerRadius = _progressBarThickness / 2.0;
_indeterminateLayer.cornerRadius = _progressBarCornerRadius;
_indeterminateLayer.opacity = 0;
[_progressBar.layer addSublayer:_indeterminateLayer];

Expand Down Expand Up @@ -185,6 +186,19 @@ - (void)setProgressBarThickness:(CGFloat)progressBarThickness
[self invalidateIntrinsicContentSize];
}

- (void)setProgressBarCornerRadius:(CGFloat)progressBarCornerRadius
{
_progressBarCornerRadius = progressBarCornerRadius;

// Update the layer size
[self setNeedsDisplay];

// Update corner radius for layers
_progressBar.layer.cornerRadius = _progressBarCornerRadius;
_indeterminateLayer.cornerRadius = _progressBarCornerRadius;
[self invalidateIntrinsicContentSize];
}

#pragma mark Actions

- (void)setProgress:(CGFloat)progress animated:(BOOL)animated
Expand Down
2 changes: 2 additions & 0 deletions M13ProgressSuite/BarViewController.h
Expand Up @@ -23,6 +23,7 @@
@property (nonatomic, retain) IBOutlet UIButton *animateButton;
@property (nonatomic, retain) IBOutlet UISegmentedControl *iconControl;
@property (nonatomic, retain) IBOutlet UISwitch *indeterminateSwitch;
@property (nonatomic, retain) IBOutlet UISwitch *cornerRadiusSwitch;
@property (nonatomic, retain) IBOutlet UISwitch *showPercentageSwitch;
@property (nonatomic, retain) IBOutlet UISegmentedControl *positionControl;
@property (nonatomic, retain) IBOutlet UISegmentedControl *directionControl;
Expand All @@ -31,6 +32,7 @@
- (IBAction)progressChanged:(id)sender;
- (IBAction)iconChanged:(id)sender;
- (IBAction)indeterminateChanged:(id)sender;
- (IBAction)cornerRadiusChanged:(id)sender;
- (IBAction)showPercentage:(id)sender;
- (IBAction)percentagePositionChangeed:(id)sender;
- (IBAction)directioChanged:(id)sender;
Expand Down
10 changes: 10 additions & 0 deletions M13ProgressSuite/BarViewController.m
Expand Up @@ -38,6 +38,10 @@ - (void)viewDidLoad
//Set the percentage position
_progressViewVertical.percentagePosition = M13ProgressViewBarPercentagePositionTop;
_progressViewHorizontal.percentagePosition = M13ProgressViewBarPercentagePositionTop;

// Remove corner radius
_progressViewVertical.progressBarCornerRadius = 0.0;
_progressViewHorizontal.progressBarCornerRadius = 0.0;
}

- (void)didReceiveMemoryWarning
Expand Down Expand Up @@ -92,6 +96,12 @@ - (void)indeterminateChanged:(id)sender
[_progressViewVertical setIndeterminate:_indeterminateSwitch.on];
}

- (IBAction)cornerRadiusChanged:(id)sender
{
[_progressViewHorizontal setProgressBarCornerRadius:_cornerRadiusSwitch.on ? _progressViewHorizontal.progressBarThickness / 2.0 : 0.0];
[_progressViewVertical setProgressBarCornerRadius:_cornerRadiusSwitch.on ? _progressViewVertical.progressBarThickness / 2.0 : 0.0];
}

- (void)animateProgress:(id)sender
{
//Disable other controls
Expand Down

0 comments on commit dc82201

Please sign in to comment.