Seeing a behavior on iOS11 with a navigationItem.titleView where the width of the titleView is not the full width of the screen.
I have a custom view that I set as the titleView. Previous to iOS11 the view would fill the navigation bar area. But iOS 11 it is not resizing to fill the width of the screen.
I've tried setting the frame of the view before setting titleView but no luck. I've tried to force the titleViews superview to layout constraints as well but no luck.
Screenshots attached:
iOS10:
iOS11:
Anyone else experience this?
I had the same issue but with setting an
UIImage
as thenavigationItem
titleView
What i did is i scaled the image to the needed size by using the below:
And call it as follows:
The most important is that you need overwrite customTitleView as your titleView:
setting
intrinsicContentSize
toUILayoutFittingExpandedSize
works fine as wellreturn UILayoutFittingExpandedSize
not helped me, because view was added vertically few more times to fill layout.The solution was to override
intrinsicContentSize
in custom view setting width to max screen width:Fixed it by creating a subclass of UIView and assigned it to a title view of UINavigationController
Objective-C:
You can also use constraints if you don't want to override
intrinsicContentSize
. Here's a demo of SnapKitBut if there are more than one navigationbaritems on any side(left or right) navigationbar, you should use intrinsicContentSize;