UITabBar not changing color after setNeedsDisplay - ios

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.

Related

remove border of navigation bar for few view controllers

I want remove border of navigation bar. I am using this code in AppDelegate.m
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init]
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
and it works well. It removes border of navigation bar in every view controller.
But i have to remove it for few view controllers.
By placing this code in viewWillAppear of particular view controller, its not working.
Does anyone knows how to do it?
You should set the background image and shadow image of the navigation bar in your select navigations bars and not to use the appearance method. e.g.:
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];

xcode remove custom navigation image in pickerview galley

I added the following code in the appDelegate to achieve custom background images for the navigation bar.
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"Nav-Bar_01.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"Nav-Bar_02_alter.png"] forBarMetrics:UIBarMetricsDefaultPrompt];
However, I want to exclude the native gallery pickerView from this background.
Is there any way to do so without applying the background on each navigation bar alone, but keeping the same code in the appDelegate ?
I ended up placing a background image for every navigation controller instead of placing it in the App Delegate. The background was then not applied on the pickerView.
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"Nav-Bar_01"] forBarMetrics:UIBarMetricsDefault];

Have different colors on Navigation Bars?

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.

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

UINavigationBar custom background image applied in one view controller and then affecting every single view controller in the app

I am working with themes in my app. Each theme comes with a custom navigation bar. As a default, I have applied a custom navigation bar in my AppDelegate:
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
UIImage *navBackgroundImage = [UIImage imageNamed:#"purplynav.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
If I go to a specific Table View Controller in my app and in the viewWillAppear, I put:
if ([self.selectedTheme isEqualToString:#"Blur"])
{
UIImage *navBackgroundImage = [UIImage imageNamed:#"pastelpinknav.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
}
The "pastelpinknav" suddenly gets applied to every single navigation bar in my app, even though I'm only setting it in this one Table View Controller.
How do I set it so that the navigation bar only applies to this one view controller when set, but is still set to default in the App Delegate when a theme is not set?
Thanks in advance!
You have to change again the navigationBar image in viewWillDisappear
UIImage *navBackgroundImage = [UIImage imageNamed:#"purplynav.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
Because you are using [UINavigationBar appearance] it will commonly changes the UINavigationBar appearance.
From your view controller call:
[[UINavigationBar appearanceWhenContainedIn:[self class], nil] setBackgroundImage:navBackgroundImage
forBarMetrics:UIBarMetricsDefault];
Explenation:
This will change the foo color of the entire app:
[[UINavigationBar appearance] setFooColor:#"blue"]
In order to change appearance of specific container (i.e your view controller), you need to implement UIAppearanceContainer and then call (UIViewController already implements it):
[UINavigationBar appearanceWhenContainedIn:(Class<UIAppearanceContainer>), ..., nil]

Resources