Have different colors on Navigation Bars? - ios

Hi is it possible to have different colors on different Navigation Bars? I have this code in my AppDelegate.m. I basically want to be able to change the color of the different Navigation Bars in different views.
[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0xac1f2d)];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
Thanks!

You set a image to its backgorund of [UINavigationBar appearance ] in your Delegate class.

Yes you can. In your view controllers' viewWillAppear you can set --
self.navigationController.navigationBar.barTintColor to your required colour.

Related

UITabBar not changing color after setNeedsDisplay

I have an UITabBar that needs to be coloured after initialization.
I use:
[[UITabBar appearance] setTintColor:secondaryColor];
[[UITabBar appearance] setBarTintColor:primaryColor];
[[UITabBar appearance] setUnselectedItemTintColor:[secondaryColor colorWithAlphaComponent:0.5]];
This works when the color are available at start time but when I try this after creation this doesn't work until another controller is pushed & poped on the navigation stack.. after that the tabbar is properly colored. How can I force this without push/poping another controller?
I tried setNeedsDisplay on the tabbar but it doesn't work.

In Objective C, while presenting a ViewController how to change the color of NavigationBar?

I am able to change tho color of NavigationBar by giving BackgroundColor but than I am not able change the color of StatusBar. Please provide a solution.
You should change the barTintColor instead of the background color.
[self.navigationController setBarTintColor:[UIColor redNavigationBarColor]];
Chances are that you will probably need to change also the barButton color and/or the the title color and all that should probably apply to more than one screen. So, to save you some time, if you want to globally change all these, put the code below in your app delegate
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor whiteColor]}];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
The code above will give you a red navigation bar with white title & buttons

Slide Menu IOS Using aryaxt/iOS-Slide-Menu

I am trying to change Navigation bar background color in viewDidLoad using the same example in the link below but that's not working.
[[UINavigationBar appearance] setBackgroundColor:[UIColor greenColor]];
please help.
https://github.com/aryaxt/iOS-Slide-Menu
To change the NAv bar color, You have to use bar tint color:
self.navigationController.navigationBar.barTintColor=[UIColor greenColor];

iOS 7.1 UINavigationbar and UIToolbar

After upgrading Xcode in iOS7.1 my navigation bar and UIToolbar buttons are not shown with correct colour.
When a view first appears the UIToolbar buttons all have the correct default blue colour and when I go to next page/view and come back to the previous view the toolbar buttons are shown in a grey colour.
I have tried to add the blue colour in viewDidLoad and viewWillAppear but no luck. Can someone please help me?
Thanks.
You can set up a theme for certain components all at once and they will be used throughout your application. In my app delegate I created a function when the application is initializing called setupTheme, and it does just that - sets up the "theme" of the application by saying things like [[UINavigationBar appearance] setBarTintColor:], which in effect sets the color of the navigation bar for ANY navigation controller throughout the app. Here's an example from an app that sets up some basic components that are reused so that any time you use them they will already have the correct theme applied.
- (void)setupTheme {
// get our theme colors
UIColor *primaryThemeColor = [UIColor blueColor];
UIColor *secondaryThemeColor = [UIColor whiteColor];
// nav bar
[[UINavigationBar appearance] setBarTintColor:primaryThemeColor];
[[UINavigationBar appearance] setTintColor:secondaryThemeColor];
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName:secondaryThemeColor}];
// tab bar
[[UITabBar appearance] setTintColor:primaryThemeColor];
// switches
[[UISwitch appearance] setOnTintColor:primaryThemeColor];
// search bar
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:#{NSForegroundColorAttributeName: [UIColor blackColor]} forState:UIControlStateNormal];
}
Check out the iOS 7 transition guide for more details on specifics https://developer.apple.com/library/iOs/documentation/UserExperience/Conceptual/TransitionGuide/Bars.html#//apple_ref/doc/uid/TP40013174-CH8-SW1

How to make a custom UIView to combine with UINavigationBar make it looks as one

As you can see below, the three buttons: STORE,AREA and All. These buttons looks like the UINavigationBar and them are combined together. I tried in storyboard, I added a custom UIView and try to set it's colour match the UINavigationBar background color. But it always has differences, and I can see the border line between UINavigationBar and the custom UIView. How to make a UIView to combine with the UINavigationBar to make it all looks like they are combined.
iOS 7 has shadow next to the navigation bar. Try below to remove that shadow:
if (IS_IOS7) {
[[UINavigationBar appearance]setShadowImage:[[UIImage alloc] init]];
}
You can change the navigation and status bar background only in iOS7. For this, you can use
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];
The size of the nav_bg.png should be 320*64 px
If you want to simply change the color of navigation bar you can use
[[UINavigationBar appearance] setBarTintColor:[UIColor blueColor]];

Resources