|
17 | 17 | static char indeterminateKey; |
18 | 18 | static char indeterminateLayerKey; |
19 | 19 | static char isShowingProgressKey; |
| 20 | +static char primaryColorKey; |
| 21 | +static char secondaryColorKey; |
20 | 22 |
|
21 | 23 | @implementation UINavigationController (M13ProgressViewBar) |
22 | 24 |
|
@@ -156,6 +158,9 @@ - (void)updateProgressWithInterfaceOrientation:(UIInterfaceOrientation)interface |
156 | 158 | { |
157 | 159 | progressView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 2.5)]; |
158 | 160 | progressView.backgroundColor = self.navigationBar.tintColor; |
| 161 | + if ([self getPrimaryColor]) { |
| 162 | + progressView.backgroundColor = [self getPrimaryColor]; |
| 163 | + } |
159 | 164 | progressView.clipsToBounds = YES; |
160 | 165 | [self setProgressView:progressView]; |
161 | 166 | } |
@@ -243,11 +248,32 @@ - (void)drawIndeterminateWithInterfaceOrientation:(UIInterfaceOrientation)interf |
243 | 248 | //Start the image context |
244 | 249 | UIGraphicsBeginImageContextWithOptions(CGSizeMake(stripeWidth * 4.0, stripeWidth * 4.0), NO, [UIScreen mainScreen].scale); |
245 | 250 | //Fill the background |
| 251 | + if ([self getPrimaryColor]) { |
| 252 | + [[self getPrimaryColor] setFill]; |
| 253 | + } else { |
246 | 254 | [self.navigationBar.tintColor setFill]; |
| 255 | + } |
247 | 256 | UIBezierPath *fillPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, stripeWidth * 4.0, stripeWidth * 4.0)]; |
248 | 257 | [fillPath fill]; |
249 | 258 | //Draw the stripes |
250 | | - [self.navigationBar.barTintColor setFill]; |
| 259 | + //Set the stripe color |
| 260 | + if ([self getSecondaryColor]) { |
| 261 | + [[self getSecondaryColor] setFill]; |
| 262 | + } else { |
| 263 | + CGFloat red; |
| 264 | + CGFloat green; |
| 265 | + CGFloat blue; |
| 266 | + CGFloat alpha; |
| 267 | + [self.navigationBar.barTintColor getRed:&red green:&green blue:&blue alpha:&alpha]; |
| 268 | + //System set the tint color to a close to, but not non-zero value for each component. |
| 269 | + if (alpha > .05) { |
| 270 | + [self.navigationBar.barTintColor setFill]; |
| 271 | + } else { |
| 272 | + [[UIColor whiteColor] setFill]; |
| 273 | + } |
| 274 | + |
| 275 | + } |
| 276 | + |
251 | 277 | for (int i = 0; i < 4; i++) { |
252 | 278 | //Create the four inital points of the fill shape |
253 | 279 | CGPoint bottomLeft = CGPointMake(-(stripeWidth * 4.0), stripeWidth * 4.0); |
@@ -423,4 +449,27 @@ - (BOOL)isShowingProgressBar |
423 | 449 | return objc_getAssociatedObject(self, &isShowingProgressKey); |
424 | 450 | } |
425 | 451 |
|
| 452 | +- (void)setPrimaryColor:(UIColor *)primaryColor |
| 453 | +{ |
| 454 | + objc_setAssociatedObject(self, &primaryColorKey, primaryColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC); |
| 455 | + [self getProgressView].backgroundColor = primaryColor; |
| 456 | + [self setIndeterminate:[self getIndeterminate]]; |
| 457 | +} |
| 458 | + |
| 459 | +- (UIColor *)getPrimaryColor |
| 460 | +{ |
| 461 | + return objc_getAssociatedObject(self, &primaryColorKey); |
| 462 | +} |
| 463 | + |
| 464 | +- (void)setSecondaryColor:(UIColor *)secondaryColor |
| 465 | +{ |
| 466 | + objc_setAssociatedObject(self, &secondaryColorKey, secondaryColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC); |
| 467 | + [self setIndeterminate:[self getIndeterminate]]; |
| 468 | +} |
| 469 | + |
| 470 | +- (UIColor *)getSecondaryColor |
| 471 | +{ |
| 472 | + return objc_getAssociatedObject(self, &secondaryColorKey); |
| 473 | +} |
| 474 | + |
426 | 475 | @end |
0 commit comments