user580175
user580175

Reputation:

UITableView under transparent navigation bar

I'm trying to layout a tableview in a UIViewController with a transparent navigationBar. I already accomplished this, using this code on my custom UINavigationController:

navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationBar.shadowImage = UIImage()
navigationBar.isTranslucent = true

On my storyboard I set my tableView with its edges pinned to the safe area, except for the top one, who is pinned to the top of the super view.

Problem is that my tableView is not starting at the top of the screen but as if the navigation bar is still opaque. I check the tableView insets and all are zero. What I'm doing wrong here?

Thanks

Upvotes: 0

Views: 2330

Answers (2)

Konstantin Stolyarenko
Konstantin Stolyarenko

Reputation: 136

Swift 5.8.1 variant :

if #available(iOS 11.0, *) {
   tableView.contentInsetAdjustmentBehavior = .never
} else {
   automaticallyAdjustsScrollViewInsets = false
}

Upvotes: 0

Kerberos
Kerberos

Reputation: 4166

You can try to disable the scroll view insets adjustment.

contentInsetAdjustmentBehavior is available from iOS11 so you can check the availability like in this code:

if (@available(iOS 11.0, *)) 
{
    self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} 
else 
{
    self.automaticallyAdjustsScrollViewInsets = NO;
}

Upvotes: 5

Related Questions