Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color of translucent black UINavigationBar

I stumbled upon this many times, never found a solution. A UINavigationController's navigationBar can be set to black translucent like:

self.navigationController.navigationBar.barStyle=UIBarStyleBlackTranslucent; 

Also, there is a translucent property in UINavigationBar, the docs say:

When YES, the navigation bar is drawn with partial opacity, regardless of the bar style. The amount of opacity is fixed and cannot be changed. It is permissible to set the value of this property when the navigation bar is being managed by a navigation controller object.

I tried

self.navigationcontroller.navigationBar.tintColor=[UIColor blueColor]; self.navigationcontroller.navigationBar.translucent=YES; 

and a thousand variations: Setting the translucent property first, setting it in the AppDelegate and in the ViewController, setting the barstyle first. The result is always the same: No transparency. Hence my question:

Is it really possible to change the color of a translucent UINavigationBar to something different than black (preferably within a UINavigationController)?.

I hope there is a review-safe solution.

Thanks, m

like image 582
marimba Avatar asked Jul 21 '11 19:07

marimba


People also ask

How do you make the navigation bar not transparent in Swift?

You need to do three things to make a navigation bar transparent. Set background image to non-nil empty image ( UIImage() ). Set shadow image to non-nil empty image ( UIImage() ). Set isTranslucent to true .

Why is navigation bar black?

One of the issues that can occur is coloring the nav bar when your keyboard is open for typing. To fix this, head into General Settings –> Color of Navigation Bar when Keyboard is opened. Set this color to black as well. This should fix any issues you may have when the keyboard is open.


1 Answers

Once you know it, it's fairly simple:

self.navigationController.navigationBar.tintColor = [UIColor blueColor]; self.navigationController.navigationBar.alpha = 0.7f; self.navigationController.navigationBar.translucent = YES; 

The translucent property seems only to determine wether the main view should be visible under the navigation bar, and resizes the view appropiately.

like image 139
marimba Avatar answered Oct 22 '22 08:10

marimba