iOS11 customize navigation bar height

烂漫一生 提交于 2019-12-02 20:54:48

Since iOS 11 UINavigationBar fully supports Auto Layout (this is the reason why you're seeing its constraints). I've opened a radar to Apple because I thought that setting a height constraint to the titleView would have adjusted the navigation bar height accordingly. However this is what Apple replied:

Full support for auto layout does not imply that your view can influence other aspects of the layout of the navigation bar – in particular, the navigation bar enforces its own height and does not allow the title view or other custom views to exceed the height of the navigation bar. We are continuing to work on this issue, and will follow up with you again.

As of today the radar is still open.

Hello I just experienced this same issue.

Now the top layout guide is deprecated on iOS 11. You have to reference the safeAreaLayoutGuide in your constraints.

Here's an example in swift

    if #available(iOS 11, *) {
        let guide = self.view.safeAreaLayoutGuide.topAnchor
        let height = (self.navigationController?.navigationBar.frame.height)! - CGFloat(12)
        NSLayoutConstraint.activate([
        self.yourTableView.topAnchor.constraint(equalTo: guide, constant: height)
        ])
    }

As you can see your view's top anchor should match the safeAreaLayoutGuide top anchor. In this example I'm using the variable height to create the new constraint. The variable height contains the navigation bar height minus a constant.

You should try by changing the height value.

Hope this helps you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!