1
votes

I'm in the process of upgrading my app to iOS7. However I want to preserve the iOS6 interface as well. It works well except for the navigation bar(s). In iOS7 they look great (just the default color with the translucent property to YES. In iOS6 the navigation bars are showing as the default blue bars and I want them to be black translucent.

What I do is check the version of the iOS and then perform some code. In the debugger I see they right version in the vComp variable but the color is not changing. Don't mind the redColor property, that's just for the test. In both ways I am presented with the default color.

Here is my code:

- (void) fixNavBarColor:(UINavigationBar*)bar {
    NSArray *vComp = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
    if ([[vComp objectAtIndex:0] intValue] >= 7) {
        bar.barTintColor = [UIColor redColor];
        bar.translucent = NO;
    }
    else {
        bar.tintColor = [UIColor redColor];
        bar.opaque = YES;
    }
}

There is no error or warning. Any ideas?

2
Is your problem that you can't change the bar to black translucent in ios6?KudoCC
First I would get rid of NSArray *vComp = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."]; and replace the [[vComp objectAtIndex:0] intValue] >= 7 with just [[[UIDevice currentDevice] systemVersion] >= 7 this [[[UIDevice currentDevice] systemVersion] intValue] will return the value as 6 or 7 or etc no need to do a pointless componentsSeparatedByString: callPopeye
Thanx, the solution below works great. So, solved.A3O

2 Answers

2
votes

You shouldn't set the tintColor straight to navigationBar as it wouldn't be applied to other parts of your app, you should instead use UINavigationBar's appearance to set tintColor which is available on iOS 5.0 onwards.

    [[UINavigationBar appearance] setTintColor:"Your Color"];
1
votes

Use this code for iOS6

 [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithWhite:0 alpha:.8]]
                                                  forBarMetrics:UIBarMetricsDefault];