Pavel Pavel - 1 year ago 89
Swift Question

Change the alpha value of the navigation bar item in iOS Swift

In ViewDidAppear, I have changed the alpha value of the navigation bar to 0.15, but the right navigation bar item became almost invisible as well.

self.navigationController?.navigationBar.alpha = 0.15


Is it possible to change the transparency/alpha value of the right navigation bar item so that it is fully visible (alpha = 1) while having the navigation bar itself be 0.15?

Answer Source

You're setting the alpha of the entire bar to 0.15. You should be setting only the barTintColor attribute of it to a color with an alpha of 0.15 like so:

self.navigationController?.navigationBar.barTintColor = UIColor.yourColorGoesHere().colorWithAlphaComponent(0.15)