ios 11 transparent navigation bar

Robert Varga picture Robert Varga · Sep 24, 2017 · Viewed 16k times · Source

Creating a transparent navigation bar no longer works with ios 11. I get this black bar at the top because the table view doesn't come under the bar anymore (the insets in the storyboard are set properly to start from 0) Any ideas why?

enter image description here

self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true

Answer

Wujo picture Wujo · Oct 2, 2017

I faced the same problem and I was able to solve it. Here is what works for me:

public override func viewDidLoad() {
    super.viewDidLoad()
    
    self.navigationController?.navigationBar.backgroundColor = UIColor.clear
    self.navigationController?.navigationBar.isTranslucent = true
    if #available(iOS 11.0, *) {
        collectionView.contentInsetAdjustmentBehavior = .never
    } else {
        // Fallback on earlier versions
    }
}

And one more thing, that I found still necessary to make it working. Most probably you have your UICollectionView/UITableView/UIScrollview aligned to top of Safe Area. Change this constraint to be aligned to top of super view instead.

enter image description here

And that's it. Isn't it straightforward and intuitive? Thanks Apple.