Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 11 navigationItem.titleView Width Not Set

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:

enter image description here

iOS11:

enter image description here

Anyone else experience this?

like image 728
gngrwzrd Avatar asked Jul 05 '17 17:07

gngrwzrd


1 Answers

I figured it out. I had to override the intrinsicContentSize getter for the view, and the text field.

I set the width to CGFloat.greatestFiniteMagnitude so it'll always be as wide as the screen.

Update:

Since I've spent couple of hours on this issue, hope that some else will catch up faster by having all things tight up together

I've created a custom sub class of TitleView, called CustomTitleView, here's the code:

import UIKit  class CustomTitleView: UIView {    override var intrinsicContentSize: CGSize {     return UIView.layoutFittingExpandedSize   } } 

and the most important part which I missed from the start was this:

enter image description here

like image 149
gngrwzrd Avatar answered Sep 21 '22 02:09

gngrwzrd