1

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

mamadnazar
  • 60
  • 1
  • 12

2 Answers2

1

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.

Witek Bobrowski
  • 3,749
  • 1
  • 20
  • 34
  • 1
    The workaround of creating a UILabel and setting it as `self.navigationItem.leftBarButtonItem` worked pretty well, and no constraints were set in my case. Note: I didn't need no back button in the specific controller nor the collapsing feature. – mamadnazar Dec 28 '20 at 11:08
  • 1
    You may add this link https://stackoverflow.com/a/49454513/9496051 to your answer or just the solution with `self.navigationItem.leftBarButtonItem`, I will mark it as an answer – mamadnazar Dec 28 '20 at 11:08
0

For me the only working solution is:

DispatchQueue.main.async { [weak self] in
    self?.navigationController?.navigationBar.sizeToFit()
}

in

viewWillAppear()
Grenoblois
  • 503
  • 1
  • 5
  • 19