Search code examples
iosswiftuinavigationcontrollerautolayoutuinavigationbar

How to remove space that is created by prefersLargeTitles = true in Swift


How to remove the additional space that is created when you set navigationController?.navigationBar.prefersLargeTitles = true?

I understand it is navigationBar itself, but is it possible to make that largeTitle upper (right under the status bar) than its initial position which is slightly lower?

enter image description here


Solution

  • EDIT:

    This answer seems to be even better solution for the problem.

    Initial Answer:

    Not really, it is not possible to achieve without some excessive hacking which eventually will could cause problems.

    What you could do is to try to set titleView on navigation bar and set width constraint equal to the navigation bar width. Try with a simple UILabel, and set prefersLargeTitles = false and do not use navigationItem.title for this screen.

    Check out this answer

    Note that since you are not using default titles you will lose some features like collapsing the title to smaller one when scrolling a list in this screen.