Changing alpha of UINavigationBar background only?

456 Views Asked by At

I'd like to change the alpha of the UINavigationBar in my app without effecting its text and navbar elements.

I do the following in viewDidAppear of my initial view:

 self.navigationController?.navigationBar.alpha = 0.5

However, that also changes alpha on text and navbar buttons.

I also tried the following with no luck:

self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor().colorWithAlphaComponent(1)]

Is there a way to just affect the UINavigationBar background alpha?

1

There are 1 best solutions below

6
On

One way to do it, is to change the alpha value of the background color when you set the color.

For example:

self.navigationBar.barTintColor = UIColor(red: 16/255.0, green: 177/255.0, blue: 216/255.0, alpha: 0.5)

Of course you'd change the RGB values, to the color you want it to be.