Why is the navigation bar content showing on iOS 11 but not IOS 10? Why is the navigation bar content showing on iOS 11 but not IOS 10? swift swift

Why is the navigation bar content showing on iOS 11 but not IOS 10?


You need to set label's frame. titleView is subclass of UIView. So It doesn't have intrinsic contentSize. However, iOS 11 provides intrinsic content size for titleView. So you don't need to set its frame. Check this answer.

iOS 11 navigationItem.titleView Width Not Set

func title(text: String) -> UILabel {        let label = UILabel()        // add frame        label.frame = CGRect(x: 0, y: 0, width: 32, height: 32)        label.text = text        label.textColor = UIColor.black        label.font = UIFont.boldSystemFont(ofSize: label.font.pointSize)        return label    }


Try the following steps:

  1. Change view controller hierarchy to TabbarViewController > NavigationController > ViewController1, ViewController2

enter image description here

  1. Add frame to label. Navigation bar in iOS 11 could configure label's frame by its intrinsicContentSize, but earlier iOS couldn't.

  2. Set titleView by self.navigationItem.titleView = titleView. Don't use self.parent?.navigationItem.titleView = titleView.

  3. self.navigationController?.navigationBar.isHidden = false is enough, and it's not necessary to call self.parent?.navigationController?.navigationBar.isHidden = false.