Change the Alpha Value of the Navigation Bar

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

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)

Changing alpha value of navigationbar so underlying objects are visible

]you can access navigationBackgroundView

 self.navigationController?.navigationBar.isTranslucent = true
let navigationBackgroundView = self.navigationController?.navigationBar.subviews.first
navigationBackgroundView?.alpha = 0.3

Sample Image

Setting a background color with alpha in Navigation bar

If you just want the NavigationBar (excluding status bar) background with alpha.. Try this

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.navigationBar.backgroundColor = UIColor.blue.withAlphaComponent(0.5)
}

If you want background color with alpha including status bar, Im afraid you have to use an image with alpha value. see this

Edit the alpha of navigation bar when scrolls tableview

It's probably too late, but for future reference, you could do something like this:

 func scrollViewDidScroll(scrollView: UIScrollView) {
self.navigationController!.navigationBar.alpha = 1 - (self.tableView.contentOffset.y / (self.tableView.contentSize.height - self.tableView.frame.size.height));
}

On this delegate you have the values of contentOffset of scrollview or tableView, and you can observe the value of this property to make the behavior you desire.

Hope it helps!

Default Alpha value of navigation bar in Lollipop

I've made some test with navigation bar and found that alpha of navBar when android:windowTranslucentNavigation = true is 40% of black color.

So color in hex would be: #66000000

Here is steps how I calculated this value:

  1. I made screenshot as presented below
  2. Then I open it in Gimp image editor and take RGB values of each color
  3. White is (255,255,255), white under navBar (153,153,153)
  4. Grey is (150,150,150), grey under navBar (90,90,90)

Then I calculate as next:
255 is 100%
153 is x
x = 153 * 100 / 255 = 60%

So I calculated invert value of alpha channel, the true value of alpha channel is 100 - 60 = 40%

ARGB value of 40% is (102,0,0,0) in hex it's #66000000

Sample Image



Related Topics



Leave a reply



Submit