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:
- Change view controller hierarchy to TabbarViewController > NavigationController > ViewController1, ViewController2
Add frame to label. Navigation bar in iOS 11 could configure label's frame by its intrinsicContentSize, but earlier iOS couldn't.
Set titleView by
self.navigationItem.titleView = titleView
. Don't useself.parent?.navigationItem.titleView = titleView
.self.navigationController?.navigationBar.isHidden = false
is enough, and it's not necessary to callself.parent?.navigationController?.navigationBar.isHidden = false
.