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
Abstract Class and Abstract Function in Swift
Arkit - Place a Scnplane Between 2 Vector Points on a Plane in Swift 3
How to Have a Searchbar Which Shows Suggestions with Different UItableview
iOS Charts - Single Values Not Showing Swift
A Warning "'Init()' Is Deprecated". [Swift, iOS App, Learning Model]
Is There an Object Class in Swift
Add Custom .Colornames to UIcolor Somehow
Heightanchor.Constraint Not Change Height of View
Why Is There Multiple Collision Calls Sprite Kit Swift
How to Properly Map JSON Properties to Model Properties in Realm.Create
Create Objects/Instances in Variables Swift
Query Value Between Two Other Values in Firebase
How to Get Parallax Effect on UIbutton in Tvos
Cannot Assign Value of Type 'Menuview' to Type 'some View'
Spritekit: Sprites Are Moving Through Each Other with a Physicsbody Already Set