Navigation Bar Title View Missing in iOS11

iOS 11 Navigation TitleView misplaced

Here's how it can be fixed -

Add this code in the custom title view class -

override var intrinsicContentSize: CGSize {
return UILayoutFittingExpandedSize
}

And the custom title view shows up at the correct position.

Navigation Bar Title Not Showing

Try to set the view controller's title property to "Hello"

self.title = "Hello"

If it works, you can find an explanation in AWebster's answer here Swift - Title Not Appearing for Navigation View Controller

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
}


Related Topics



Leave a reply



Submit