iosuinavigationbarios10ios11titleview

iOS 11 Navigation TitleView misplaced


I have an iOS app in which I am setting a custom navigation title view.

It was working fine till iOS 10, but in iOS 11 the navigation title view is misplaced.

Here is the screen shot for iOS 10 -

The title view looks fine

Here is the screen shot for iOS 11 -

The title view is shifted down

As you can see in the screen shots that when I run the code on iOS 10 the title view appears to be fine. But the same code on iOS 11 shifts the title view down by some pixels and it gets cut.

This is how I am setting the title view -

navigationItem.titleView = MY_CUSTOM_TITLE_VIEW

I tried many things and searched for many solutions but nothing is working.


Solution

  • 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.