UITabBar tintColor is not changed storyboard - ios

I have set a global tintColor, and I can see it in the interface builder, when I select UITabBar as well as UITabBarController, still when I run the application, the tint of the selected UITabBarItem is iOS default (blue), and not what I have set. What am I missing?
P.S.
UITabBarController is pushed to navigationController, it is not the rootViewController

Storyboard doesn't support that directly yet. But you can set an user defined runtime attribute in storyboard.
Select the tab bar of the tab bar controller.
Select the identity inspector. (The view where you can set the class of a view.)
And if you want to change the selected item's tint color instead, just use the selectedImageTintColor Key Path instead.

Use this code in didFinishLaunchingWithOptions: method of your appDelegate
[[UITabBar appearance] setSelectedImageTintColor: [UIColor redColor]];
Replace red color with color you want.

If you are targeting iOS 8 then
selectedImageTintColor is deprecated in iOS 8 use tintColor
Swift
UITabBar.appearance().tintColor = UIColor.redColor()
Objective c
[[UITabBar appearance] setTintColor: [UIColor redColor]];

In my application, I wanted each ViewController to have a unique TabBarItem color when presented.
In iOS 8, the manual addition of a tintColor attribute in the storyboard worked fine, but no longer has any effect under iOS 9 / Xcode 8.
I solved the problem by including the following code in each of my TabBarController's children ViewControllers, overriding each of their ViewDidAppear() functions.
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.tabBarController?.tabBar.tintColor = UIColor.whateverColor
//The rest of your code
}
This is safe in any ViewController, due to the ? after the tabBarController call. If the ViewController is not embedded in a TabBarController, the entire line is simply ignored.
By placing this code in each of your VCs, you can specify the color of each TabBarItem easily.

Related

View Controller Top Bar not editing

In my view controller, I have changed the color of the top bar in the simulated metrics, I have changed it to be 'Translucent Black navigation bar', but when I start up my app in the simulator my top bar is still white.
BarSimulated metrics only affect how the NavigationBar's overview is displayed in the Interface Builder. The actual NavigationBar is either part of your viewController's navigationController or a view you added manually.
With UINavigationcontroller:
self.navigationcontroller.navigation.translucent = false
With custom UINavigationBar:
self.myNavigationBar.translucent = false
Try setting the NavigationBar tint colour as following screenshot.
Simulated metrics exist just that you can see what it will look like on launch. It doesn't really affect your app.
If you want to change your navigationBar's color, you must do it programmatically:
SWIFT
// in ViewController
navigationController.navigationBar.barTintColor = UIColor.greenColor()
OBJ C
// in ViewController
self.navigationBar.barTintColor = [UIColor greenColor];

change navigation bar color of specific controller

I have set a color of my Navigation bar in Appdelegate so my app uses same color for all the navigation appearing in different screens. But Now for one or two controllers I want to change the navigation color. I used this code in viewDidLoad of specific controller but It isn't working
self.navigationController?.navigationBar.backgroundColor = UIColor.whiteColor()
I have tried this code in viewWillAppear function too but still it doesn't work
The property you are looking for is not backgroundColor, but rather barTintColor.
self.navigationController?.navigationBar.barTintColor = UIColor.whiteColor()
Please use tint color
[nav.navigationBar setBarTintColor:[UIColor blueColor]];

Is there a way to change the back button color when using the navigation controller in Xcode [duplicate]

I'm having problems trying to figure out how to change the color of the buttons on the navigation controller.
Previously I had used the following:
[[UIBarButtonItem appearance] setTintColor:[UIColor colorWithRed:226/255.0 green:66/255.0 blue:66/255.0 alpha:0.0]];
and this worked, but I added a new view with a toolbar, and the tool bar button images will not show. If I remove the global coloring, the tool bar items show just fine.
I've tried setting the tint color on both the leftBarButtonItem and the backBarButtonItem in the viewDidLoad method of the view, but both of those properties appear to be null.
I don't want to change the color of the entire navigation bar, just the buttons. Is there a way to do this?
Yeah, I'll just post this as an answer. Your alpha is set to 0. So you're basically saying the same thing as [UIColor clearColor].
Not sure how that ever worked to give you a tint color on your bar button items.
In swift, it can be accomplished by the following command:
if let navController = self.navigationController
{
navController.navigationBar.tintColor = UIColor.whiteColor()
}

iOS - How to change color of icons in tab bar moreViewController

I want to change color of icons (and probably badge) in moreNavigationController from gray to something else.
I've read and successfully changed color of background and text. I did this by "replacing" data source of moreViewController (described e.g. here Customizing the More menu on a Tab bar ). But updating icons (also textLabel value) here makes no effect. Is it possible to change this gray color to white (or anything else)? Or I have to implement my own tabBarController? (any good tutorials?)
PS. I know how to change icons on tab bar itself, the question is how to do this in moreViewController?
Thanks!
Piotr
In case it is still relevant to anyone.
You can change icon colors displayed in a tableView of moreViewController:
self.tabBarController?.moreNavigationController.topViewController?.view.tintColor = UIColor.redColor()
Changing a title is like so:
self.tabBarController?.moreNavigationController.navigationBar.topItem?.title = "MyString"
Changing Edit button:
self.tabBarController?.moreNavigationController.navigationBar.tintColor = UIColor.redColor()
You can do this using the appearance proxy, new in iOS 5. In your app delegate's didFinishLaunching method:
[[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]];
In iOS 7 use:
[[UITabBar appearance] setTintColor:[UIColor redColor]];
See the UITabBar class reference for more details.
Ok, from long research on the web and answers in this thread, it seems that it is not possible on iOS7 to change color of the icons (gray color) displayed in moreViewController of UITabBarController. The best solution for customizable tab bar is to implement it (or use some library).
Thanks!
You can change the color, just subclass the tab bar controller and in it's view did load add the below code
override func viewDidLoad() {
super.viewDidLoad()
var view = self.moreNavigationController.topViewController.view as UITableView
view.tintColor = Utilities.mainColor()
view.separatorStyle = .None
}
For more you can see my question here : Change tint color of tabbar edit view controller

iOS 7 : Disable UINavigationBar Translucency For Entire App

Is there a way to disable UINavigationBar Translucency for an entire application?
I'm aware that using [self.navigationController.navigationBar setTranslucent:NO] can fix this issue for a single controller, but I have a lot of UINavigationBars in my application and this is a pretty tedious solution.
I've tried [[UINavigationBar appearance] setTranslucent:NO], but that functionality is surprisingly not supported. Doing that results in Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** Illegal property type, c for appearance setter, _installAppearanceSwizzlesForSetter:'
If I HAVE to, I can go through my entire app setting UINavigationBars to disable translucency one by one, but there must be some more elegant solution to this issue...
if you set the translucence of the first navigation bar in the stack to false [self.navigationController.navigationBar setTranslucent:NO], it will reflect in all the following NavigationViewController that are pushed to that stack.
Here is a Swift solution if you want to apply this Styling to the whole app.
in the AppDelegate class add this to the didFinishLaunchingWithOptions:
For Swift 2:
UINavigationBar.appearance().translucent = false
For Swift 3+:
UINavigationBar.appearance().isTranslucent = false
It seems very simple with this code in appDelegate didFinishLaunchingWithOptions (works fine with iOS 8 and above versions)
[[UINavigationBar appearance] setTranslucent:NO];
I think you are right about no appearance proxy being available for this property. Are you using UINavigationControllers or UINavigationBar objects? If you are using UINavigationBars you could subclass it and create a non-translucent nav bar.
Header file:
#import <UIKit/UIKit.h>
#interface ABCNonTranslucentNavBar : UINavigationBar
#end
Implementation file:
#import "ABCNonTranslucentNavBar.h"
#implementation ABCNonTranslucentNavBar
- (void)drawRect:(CGRect)rect
{
[self setTranslucent:NO];
}
Then just replace the UINavigationBars with your subclass. You could also do something similar with a subclassed UINavigationController.
Adding this in case anyones still battling this.
You can fool it though by specifying a non exist image, which will make the nav bar INCLUDING it's tool bar go opaque
[[UIToolbar appearance] setBackgroundColor:[UIColor colorWithRed:219.0/255.0 green:67.0/255.0 blue:67.0/255.0 alpha:1.0]];
[[UIToolbar appearance] setBackgroundImage:[[UIImage alloc] init] forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
I know this is old, but this might come in handy for someone;
You can use a category, and within it* set the property [translucent][1]
#implementation UINavigationBar (MakeTranslucent)
-(void)willMoveToWindow:(UIWindow *)newWindow {
[super willMoveToWindow:newWindow];
self.translucent = NO;
}
#end
I used willMoveToWindow, I do not know whether this is a good idea so UAYOR.
See the excerpt from UIKit code documentation:
/*
New behavior on iOS 7.
Default is YES.
You may force an opaque background by setting the property to NO.
If the navigation bar has a custom background image, the default is inferred
from the alpha values of the image—YES if it has any pixel with alpha < 1.0
If you send setTranslucent:YES to a bar with an opaque custom background image
it will apply a system opacity less than 1.0 to the image.
If you send setTranslucent:NO to a bar with a translucent custom background image
it will provide an opaque background for the image using the bar's barTintColor if defined, or black
for UIBarStyleBlack or white for UIBarStyleDefault if barTintColor is nil.
*/
Correct Swift 4 solution is
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().backgroundColor = .white
I think appearance api does not support translucent property of navigation bar .
But you can do this for whole App like this , please have a look at this code --
here Menu Screen is a root view controller .
MenuScreen *ms = [[MenuScreen alloc]initWithNibName:#"MenuScreen" bundle:nil];
UINavigationController *nv = [[UINavigationController alloc]initWithRootViewController:ms];
//This will set property for whole App.
[nv.navigationBar setTranslucent:NO];
self.window.rootViewController = nv ;
If you don't use storyboard, but IB, set the navigation bar style of your MainWindows.xib to NOT translucent and set as color not the clear color.

Resources