The navigation barTintColor doesn't change when "prefers large titles" is selected. I tried changing it from Attribute Inspector and also programmatically. I can see the color change in storyboard but not while I run the app. I have the same problem with the titleColor as well.
Yes you need to change the backgroundColor of the navigationBar for the largeTitle mode. It's completely different from the normalMode.
With Storyboard
or
With Code
navigationController?.navigationBar.backgroundColor = .brown
Result
Note that the top white area is actually the backgroundColor of the RootViewController and you need to handle it manually.
try different colors for each one and play to more understand the behavior
Related
I'm currently working on an iOS application in swift. Here I have UIView on the top of the screen and have UINavigationController. And I need the topView and navigationBar color to be same. And I gave the topBar background color and navigationBar tint color as same. But when the screen loads, the navigationController is showing a faded color. Why?
I tried through programmatically,
self.navigationController?.navigationBar.barTintColor = UIColor.red
Also, I tried through storyboard, like giving the navigationBar's tintColor as red. But in both ways, it's not working.
Please help me.
Set navigationController?.navigationBar.isTranslucent = false to have a solid color navigation bar.
By default the property translucent is set to yes which desaturates any color applied to the navigation bar.
To disable this behaviour just select the navigation bar in your storyboard and disable the checkbox labeled "translucent" in the attribute inspector.
This is very odd. My global tint is set and my icons colors are set to the default purple I have. Yet at run time its blue. Any tips? Ive checked around and have not seen anyone else with this problem.
Storyboard:
Run Time:
Basically, when you want to change the tint color of UITabBar programmatically, UITabBar class gives you several tint color properties:
tintColor: TabBarItem's color.
barTintColor : TabBar's background bar's color.
unselectedItemTintColor : color of unselected items.
so if you change the tintColor, barItems' color would be changed.
...but, Why it doesn't works on IB?
When you set a specific color to UITabBar's item in IB, there's an option named Image Tint.
Changing a Tint option on "View" section won't affect anything to TabBar's items but only Image Tint option can change tabBar's item color.
storyboard's global tint color option changes Tint option of "View" section, but doesn't affect default value of Image Tint option, so It doesn't affect the tab bar's tint color.
So.. Why Image Tint option doesn't affected?
I can't explain why doesn't it affected. Maybe Apple had an issue with this, or kind of bug.
there are some workarounds for setting an image color :
Explicitly Set an Image Tint option to UITabBarController's TabBar object.
You may should set every TabBarController's Image Tint option, because it doesn't affects global setting.
Programmatically change global UITabBar's tintColor.
At AppDelegate.swift's didFinishLaunchingWithOptions, paste following code
UITabBar.appearance().tintColor = <#Color what you want#>
I've had a similar problem, which was fixed by changing the "Render As" property to "Default" instead of "Original". You can find this in your Asset Library, when selecting your images on right right hand side under "Render As" in the attributes inspector.
In my application i would like to change color of content view not the navigation bar color
I have written like self.window.backgroundColor = [UIColor redColor]; but its changing whole content color including navigation bar color.
You could just make your UINavigationBar to not be translucent. If you are working with Interface Builder then you should go to your UINavigationController, select the UINavigationBar and uncheck the Translucent property. If you are doing this in code you can just call self.navigationBar.isTranslucent = false.
You need to set self.view.backgroundColor on any view controllers you want to adopt your new colour. Setting it on the window causes the navigation bar to change colour because it has transparency and therefore you can see the window background colour through it.
I recommend subclassing UIViewController and setting this in viewDidLayoutSubviews. Then, making all your other view controllers subclass this one. This means you don't have to write the same code for every view controller.
I am using a UIWebView to display content in an app and would like to change the color of the Done button that is displayed whenever a select control is used.
It is currently displaying as white on gray which is hard to see.
The "Done" button is white because you are probably setting the tintColor to white for all UIBarButtonItems using UIAppearance. That affects the "Done" Button in the picker view which also happens to be a UIBarButtonItem.
So you have to exclude the "Done" button in the picker view from the global white tintColor. I don't know if you only need the white UIBarButtonItems in your navigation bar, but if you do you could do this to only set the tintColor for the bar button items in your navigation bar and leave all other UIBarButtonItems untouched:
UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UINavigationBar.self]).tintColor = UIColor.whiteColor()
However this is only available in iOS9 and the old appearanceWhenContainedIn method that works for older iOS versions is not available in Swift.
So, if you are working with Swift and you have to target earlier iOS versions than iOS9 this is probably not working for you. In that case you have to remove the UIAppearance setting for the white tintColor and set the tintColor for the UIBarButtonItems in your navigation bar "manually" without using UIAppearance.
Another possible solution is to just do
UIPickerView.appearance().tintColor = UIColor.blueColor()
put this in your AppDelegate and you are ready to go!
I don't understand why the background color setting in the storyboard doesn't work for my navigation controller? (See picture)
http://ctrlv.in/299323
I have here set it to bright red but as you can see it does nothing in the storyboard or to the app when I build it.
Any thoughts?
I know I can set the color programmatically, and this is what I am currently doing. However, it would be nice to see the changes in the storyboard so I don't have to build the app every time I make a color change to see the difference.
Yes you can. Notice that you're changing UIView properties not Navigation bar. Look at the screen below:
You have to set Bar Tint property.