diff --git a/Classes/NavigationController/UINavigationController+M13ProgressViewBar.h b/Classes/NavigationController/UINavigationController+M13ProgressViewBar.h index 8fdfe45..feaf529 100644 --- a/Classes/NavigationController/UINavigationController+M13ProgressViewBar.h +++ b/Classes/NavigationController/UINavigationController+M13ProgressViewBar.h @@ -50,5 +50,11 @@ @param secondaryColor The color to set. */ - (void)setSecondaryColor:(UIColor *)secondaryColor; +/** + The background color of the progress bar, if nil, the background color will be the clearColor. + + @param background The color to set. + */ +- (void)setBackgroundColor:(UIColor *)backgroundColor; @end diff --git a/Classes/NavigationController/UINavigationController+M13ProgressViewBar.m b/Classes/NavigationController/UINavigationController+M13ProgressViewBar.m index cf02913..ba0e7fd 100644 --- a/Classes/NavigationController/UINavigationController+M13ProgressViewBar.m +++ b/Classes/NavigationController/UINavigationController+M13ProgressViewBar.m @@ -20,6 +20,8 @@ static char isShowingProgressKey; static char primaryColorKey; static char secondaryColorKey; +static char backgroundColorKey; +static char backgroundViewKey; @implementation UINavigationController (M13ProgressViewBar) @@ -91,8 +93,8 @@ - (void)animateProgress:(CADisplayLink *)displayLink - (void)finishProgress { UIView *progressView = [self getProgressView]; - - if (progressView) { + UIView *backgroundView = [self getBackgroundView]; + if (progressView && backgroundView) { dispatch_async(dispatch_get_main_queue(), ^{ [UIView animateWithDuration:0.1 animations:^{ CGRect progressFrame = progressView.frame; @@ -101,8 +103,11 @@ - (void)finishProgress } completion:^(BOOL finished) { [UIView animateWithDuration:0.5 animations:^{ progressView.alpha = 0; + backgroundView.alpha = 0; } completion:^(BOOL finished) { [progressView removeFromSuperview]; + [backgroundView removeFromSuperview]; + backgroundView.alpha = 1; progressView.alpha = 1; [self setTitle:nil]; [self setIsShowingProgressBar:NO]; @@ -115,14 +120,18 @@ - (void)finishProgress - (void)cancelProgress { UIView *progressView = [self getProgressView]; - - if (progressView) { + UIView *backgroundView = [self getBackgroundView]; + + if (progressView && backgroundView) { dispatch_async(dispatch_get_main_queue(), ^{ [UIView animateWithDuration:0.5 animations:^{ progressView.alpha = 0; + backgroundView.alpha = 0; } completion:^(BOOL finished) { [progressView removeFromSuperview]; + [backgroundView removeFromSuperview]; progressView.alpha = 1; + backgroundView.alpha = 1; [self setTitle:nil]; [self setIsShowingProgressBar:NO]; }]; @@ -154,9 +163,11 @@ - (UIInterfaceOrientation)currentDeviceOrientation - (void)showProgress { UIView *progressView = [self getProgressView]; + UIView *backgroundView = [self getBackgroundView]; [UIView animateWithDuration:.1 animations:^{ progressView.alpha = 1; + backgroundView.alpha = 1; }]; [self setIsShowingProgressBar:YES]; @@ -174,14 +185,31 @@ - (void)updateProgressWithInterfaceOrientation:(UIInterfaceOrientation)interface if(!progressView) { progressView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 2.5)]; - progressView.backgroundColor = self.navigationBar.tintColor; - if ([self getPrimaryColor]) { - progressView.backgroundColor = [self getPrimaryColor]; - } progressView.clipsToBounds = YES; [self setProgressView:progressView]; } + if ([self getPrimaryColor]) { + progressView.backgroundColor = [self getPrimaryColor]; + } else { + progressView.backgroundColor = self.navigationBar.tintColor; + } + + //Create background view if it doesn't exist + UIView *backgroundView = [self getBackgroundView]; + if (!backgroundView) + { + backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 2.5)]; + backgroundView.clipsToBounds = YES; + [self setBackgroundView:backgroundView]; + } + + if ([self getBackgroundColor]) { + backgroundView.backgroundColor = [self getBackgroundColor]; + } else { + backgroundView.backgroundColor = [UIColor clearColor]; + } + //Calculate the frame of the navigation bar, based off the orientation. UIView *topView = self.topViewController.view; CGSize screenSize; @@ -209,6 +237,7 @@ - (void)updateProgressWithInterfaceOrientation:(UIInterfaceOrientation)interface //Check if the progress view is in its superview and if we are showing the bar. if (progressView.superview == nil && [self isShowingProgressBar]) { + [self.navigationBar addSubview:backgroundView]; [self.navigationBar addSubview:progressView]; } @@ -222,7 +251,7 @@ - (void)updateProgressWithInterfaceOrientation:(UIInterfaceOrientation)interface //Calculate the width of the progress view progressView.frame = CGRectMake(0, height - 2.5, width, 2.5); } - + backgroundView.frame = CGRectMake(0, height - 2.5, width, 2.5); } - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration @@ -437,6 +466,17 @@ - (UIView *)getProgressView return objc_getAssociatedObject(self, &progressViewKey); } +- (void)setBackgroundView:(UIView *)view +{ + objc_setAssociatedObject(self, &backgroundViewKey, view, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (UIView *)getBackgroundView +{ + return objc_getAssociatedObject(self, &backgroundViewKey); +} + + - (void)setIndeterminate:(BOOL)indeterminate { objc_setAssociatedObject(self, &indeterminateKey, [NSNumber numberWithBool:indeterminate], OBJC_ASSOCIATION_RETAIN_NONATOMIC); @@ -488,4 +528,15 @@ - (UIColor *)getSecondaryColor return objc_getAssociatedObject(self, &secondaryColorKey); } +- (void)setBackgroundColor:(UIColor *)backgroundColor +{ + objc_setAssociatedObject(self, &backgroundColorKey, backgroundColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + [self setIndeterminate:[self getIndeterminate]]; +} + +- (UIColor *)getBackgroundColor +{ + return objc_getAssociatedObject(self, &backgroundColorKey); +} + @end diff --git a/M13ProgressSuite/Base.lproj/Main_iPhone.storyboard b/M13ProgressSuite/Base.lproj/Main_iPhone.storyboard index d2b2da8..d71cf48 100644 --- a/M13ProgressSuite/Base.lproj/Main_iPhone.storyboard +++ b/M13ProgressSuite/Base.lproj/Main_iPhone.storyboard @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -10,21 +14,21 @@ - + - + - + - + - + - + - + - +