iOS 11 navigationItem.titleView Width Not Set iOS 11 navigationItem.titleView Width Not Set ios ios

iOS 11 navigationItem.titleView Width Not Set


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 UIKitclass 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


Using @falkon's answer here's the code:

Add this code to the view that is used as titleView

override var intrinsicContentSize: CGSize {    return UILayoutFittingExpandedSize} 


Fixed it by creating a subclass of UIView and assigned it to a title view of UINavigationController

Objective-C:

#import "FLWCustomTitleView.h"@implementation FLWCustomTitleView- (CGSize )intrinsicContentSize {  return UILayoutFittingExpandedSize;}@end

enter image description hereenter image description here