Styling UINavigationBar to match the style in UINavigationController - ios

I have a tap bar that with 3 items. The first item is a UISplitView showing a UIViewController with a UITableView. The other two items are simple UIViewControllers embedded in a UINavigationController.
The two UIViewControllers embedded in a UINavigationController have a navigation bar with their title provided by the UINavigationController and "default" color.
I added a UINavigationBar to the UINavigationController in the first item but it has different color, it is white (Messages in the gif):
So I found out the default color of the UINavigationBar embedded in a UINavigationController and set it in code
navigationBar.barTintColor = UIColor(colorLiteralRed: (247/255), green: (247/255), blue: (247/255), alpha: 1)
The navigation bar changes color but the status bar remains white:
I tried the accepted answer from How to change Status Bar text color in iOS 7 but it did not help.
So how do I style the UINavigationBar in my view controller so it exactly matches the default one in navigation controller?

I think we worked together at Fuerte International a couple of years ago!
The status bar doesn't have a colour, it should just be the colour of your background view. Change the colour of that and you should see the status bar change too?

Related

Separate colors for viewcontroller background and statusbar background

I want a blue color for my navigation bar and status bar backgrounds while a white color background for the rest of the view controller. I want this for all my view controllers in the app. Naturally, I have in my BaseViewContrller for statusbar:
self.view.backgroundColor = UIColor.blue
But this causes the whole view controller to go blue. Is adding a white UIView and constraining it to safe areas the only option or there is an easy way to accomplish this?
Yes, because you're setting ViewController's view background color and not navigationBar background color. Instead set background color of navigation bar
navigationController?.navigationBar.backgroundColor = .blue

NavigationBar barTintColor showing different effect for same color

I am trying to set color to navigation bar for different controllers but same color showing different effect.
Add following line to your viewDidLoad:method of navigationController class,
self.navigationBar.translucent = NO;
Visit navigationBar translucent property.

UINavigationBar isTranslucent false but maintain transparency

I currently have a project set up where for during sign up I am using a UINavigationController to manage the view controllers, and as part of the design I set the UINavigationBar to be transparent with the following code:
let navBar: UINavigationBar! = self.navigationController?.navigationBar
navBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
navBar.shadowImage = UIImage()
navBar.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)
navBar.tintColor = UIColor.white
navBar.barTintColor = UIColor.clear
This allows me to use the navigation controller's heirarchy to manage the backwards/forwards movement, and works fine, except that when I show a view controller, any view that I have (set up through Autolayout) does a "jumping" motion to get into its correct position (just like this question's video https://vid.me/9kB5). Some searching led me to try the following 2 solutions
1.) Uncheck Extend Edges - Under Top Bars in my storyboard view controller
2.) Set translucency for the nav bar to false
navBar.isTranslucent = false
This solves the jumping motion and causes the views to be in place when they load, but the problem with this is that the navigation bar now becomes the barTintColor (which for UIColor.clear ends up being black). It seems I am unable to keep both transparency and translucency at the same time. A lot of similar questions on Stack have navigation bars with set colors and not transparent.
The next approach I thought of would be that I would have to get rid of the UINavigationController, and instead implement back buttons on each of my sign up view controllers, but I was hoping to try and tackle this with the navigation controller.
Is it possible to have a UINavigationBar have translucency set to false but maintain transparency?
EDIT: Here's a picture of what the nav bar looks like with the isTransluscent = false code:
Try changing "alpha" property. Make sure that everything you do with navigation bar you do on the main thread.
Solution 2: you can set specific UIImage for your navigation bar background.

How do I change the colors of each TabBar navigation bar title individually?

I have a TabBar with 5 tabs. For each tab, I want them to have a different navigation bar color. How can I have a different color for each item?
For all other navigation bar titles, I'd like them to have black color.
You need to set at each view controller the bar color with this code:
UINavigationBar.appearance().barTintColor = UIColor .redColor
While this is to set your bar titles to black:
UINavigationBar.appearance().tintColor = UIColor.blackColor()
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.blackColor()]
In the storyboard you'll probably see a navigation controller for each tab:
Select one of these controllers and then in the document outline select the navigation bar:
Next, in the Attributes Inspector, modify the background color:
You don't need to do anything to get black navigation bar title text. That's the default.
VoilĂ !!

make nav bar color same has uibutton swift

I got this colour UIColor(red:0.26, green:0.5, blue:0.82, alpha:1.0)
When I applied it to uibutton and nav bar I like the nav bar color better than the original colour applied to the button . How do i get that color?
Here is pic
Your navigation bar is translucent, so its visible color is slightly lighter than the tintColor.
You can get rid of the translucency using :
self.navigationBar.translucent = false
But if you want to keep the translucent effect, for example if you use an UIScrollView, then i suggests you to refer to this question. which provides a calculator to get the correct tintColor.

Resources