From 88c2ea0c5a8847d25c01b0d72a9161e8ab0c9195 Mon Sep 17 00:00:00 2001 From: zsading Date: Wed, 6 Apr 2016 18:20:37 +0800 Subject: [PATCH] Add some custom function 1.Add custom view border color 2.Add custom progress bar color --- .../ViewController.m | 3 +++ .../GBKUIButtonProgressView.h | 7 +++++- .../GBKUIButtonProgressView.m | 25 ++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Example/GBKUIButtonProgressViewExample/GBKUIButtonProgressViewExample/ViewController.m b/Example/GBKUIButtonProgressViewExample/GBKUIButtonProgressViewExample/ViewController.m index 9aed9ca..52df99e 100644 --- a/Example/GBKUIButtonProgressViewExample/GBKUIButtonProgressViewExample/ViewController.m +++ b/Example/GBKUIButtonProgressViewExample/GBKUIButtonProgressViewExample/ViewController.m @@ -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 { diff --git a/GBKUIButtonProgressView/GBKUIButtonProgressView.h b/GBKUIButtonProgressView/GBKUIButtonProgressView.h index 122edf6..f057338 100644 --- a/GBKUIButtonProgressView/GBKUIButtonProgressView.h +++ b/GBKUIButtonProgressView/GBKUIButtonProgressView.h @@ -8,6 +8,9 @@ #import +static NSString * const GBKBorderColorAttributeName = @"GBKBorderColorAttributeName"; +static NSString * const GBKProgessColorAttributeName = @"GBKProgessColorAttributeName"; + @interface GBKUIButtonProgressView : UIView @property (strong, nonatomic) NSString *completeTitle; @@ -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 diff --git a/GBKUIButtonProgressView/GBKUIButtonProgressView.m b/GBKUIButtonProgressView/GBKUIButtonProgressView.m index a075279..08a8317 100644 --- a/GBKUIButtonProgressView/GBKUIButtonProgressView.m +++ b/GBKUIButtonProgressView/GBKUIButtonProgressView.m @@ -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; @@ -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; @@ -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 { @@ -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