Reputation: 43
I'm trying to find a way to modify the style of my UINavigationBar without using images. I want to create a flat UINavigationBar with a solid color. Is my only option to subclass UINavigationBar and draw the complete NavigationBar myself? I'm targeting iPhones running iOS 6.0.
Upvotes: 4
Views: 765
Reputation: 4914
you can use UINavigationBar appearance
here you go, edit rgb values of colors as you need
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:1/256.0 green:96/256.0 blue:149/256.0 alpha:1.0]];
return YES;
}
Note: this wont effect bar button items , you have to look at [[UIBarButtonItem appearance]
if you want to change buttons too
[[UIBarButtonItem appearance] setTintColor:[UIColor colorWithRed:126/256.0 green:181/256.0 blue:55/256.0 alpha:1.0]];
Upvotes: 5