A3O
A3O

Reputation: 513

Change color of navigation bar ios6 and ios7

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?

Upvotes: 1

Views: 1425

Answers (2)

ldindu
ldindu

Reputation: 4380

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"];

Upvotes: 2

NANNAV
NANNAV

Reputation: 4901

Use this code for iOS6

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

Upvotes: 1

Related Questions