Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ - (void)viewDidLoad {
[self.downloadButton addTarget:self action:@selector(downloadButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
self.downloadButton.initialTitle = @"Download";
self.downloadButton.completeTitle = @"Open";

// [self.downloadButton setProgressWithCustomColor:[UIColor redColor]];
// [self.downloadButton setViewWithCustomAttributeDictionary:@{GBKBorderColorAttributeName:[UIColor orangeColor]}];
}

-(void)downloadButtonPressed:(id)sender {
Expand Down
7 changes: 6 additions & 1 deletion GBKUIButtonProgressView/GBKUIButtonProgressView.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

#import <UIKit/UIKit.h>

static NSString * const GBKBorderColorAttributeName = @"GBKBorderColorAttributeName";
static NSString * const GBKProgessColorAttributeName = @"GBKProgessColorAttributeName";

@interface GBKUIButtonProgressView : UIView

@property (strong, nonatomic) NSString *completeTitle;
Expand All @@ -25,5 +28,7 @@
- (void)setProgress:(CGFloat)progress animated:(BOOL)animated withCompletion:(void(^)())completion;
- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;


//custom
- (void)setViewWithCustomAttributeDictionary:(NSDictionary *)dict;
- (void)setProgressWithCustomColor:(UIColor *)progressColor;
@end
25 changes: 24 additions & 1 deletion GBKUIButtonProgressView/GBKUIButtonProgressView.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ @interface GBKUIButtonProgressView()
@property (strong, nonatomic) CAShapeLayer *arc;

@property (nonatomic) float expandDuration;
@property (strong,nonatomic) UIColor *progressColor;

// initial -> shrinking -> progressing -> expanding -> completed
@property (assign, nonatomic) GBKUIButtonProgressState state;
Expand Down Expand Up @@ -180,7 +181,7 @@ - (void) createArcView {
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:self.arcContainer.center radius:radius-0.5 startAngle:DEGREES_TO_RADIANS(270) endAngle:DEGREES_TO_RADIANS(269) clockwise:YES];
self.arc.path = path.CGPath;
self.arc.fillColor = [UIColor clearColor].CGColor;
self.arc.strokeColor = self.tintColor.CGColor;
self.arc.strokeColor = self.progressColor.CGColor;
self.arc.lineWidth = strokeWidth;

self.arc.strokeStart = 0;
Expand Down Expand Up @@ -367,6 +368,14 @@ -(BOOL)isComplete {
return self.state == GBKUIButtonProgressCompleted || self.state == GBKUIButtonProgressExpandingToComplete;
}

-(UIColor *)progressColor{

if (_progressColor) {
return _progressColor;
}
return self.tintColor;
}

#pragma mark - Event Handling Notifications

- (IBAction)eventTouchUp:(id)sender {
Expand All @@ -391,4 +400,18 @@ - (void)animateTouchDown {
[GBKUIButtonAnimations applyTouchDownAnimationForView:self];
}

#pragma mark - Custom Methods

- (void)setViewWithCustomAttributeDictionary:(NSDictionary *)dict{

if (dict[GBKBorderColorAttributeName]) {
UIColor *borderColor = dict[GBKBorderColorAttributeName];
self.borderView.layer.borderColor = borderColor.CGColor;
}
}


- (void)setProgressWithCustomColor:(UIColor *)progressColor{
self.progressColor = progressColor;
}
@end