'How do I turn off large titles for UINavigationBar?

I have a UITableView and a Detail View embedded in a UINavigationController as so: enter image description hereI would like to turn on large titles for "My Notes" but I'd like to turn it off for the detail view. Something like how the default Mail app works on iPhone. How would I change the navigation bar's prefersLargeTitle property during that segue?



Solution 1:[1]

SwiftUI version

.navigationBarTitle("Title", displayMode: .inline)

Solution 2:[2]

Any one of both of following, will solve your problem:

  1. set prefersLargeTitles to false for your navigationBar

    self.navigationController?.navigationBar.prefersLargeTitles = false
    
  2. set largeTitleDisplayMode to never for navigationItem (note: prefersLargeTitles must be false otherwise this won't work)

    self.navigationController?.navigationItem.largeTitleDisplayMode = .never
    

Note: if prefersLargeTitles is true, then largeTitleDisplayMode = .never won't work. Small title display for navigation bar is dependent on prefersLargeTitles

This will enable large title mode if it's value is true

self.navigationController?.navigationBar.prefersLargeTitles = true

Solution 3:[3]

I had the same issue just now.

My use case:

MasterVC: basic navigation bar without largeTitle

DetailVC: largeTitle enabled

--> When going back to the MasterVC from the DetailVC I was seeing a weird animation which showed a largeTitle on the Master for a sec before going back to the basic non largeTitle layout. It looked like a glitch.

I fixed it by following this approach:

In MasterVC - viewDidLoad

if #available(iOS 11.0, *) {
     navigationItem.largeTitleDisplayMode = .never
     navigationController?.navigationBar.prefersLargeTitles = false
}

In DetailVC - viewDidLoad

if #available(iOS 11.0, *) {
     navigationItem.largeTitleDisplayMode = .always
     navigationController?.navigationBar.prefersLargeTitles = true
} 

I hope that can help others.

Solution 4:[4]

It should be noted that if you set largeTitleDisplayMode to never, and prefersLargeTitles to false on a detail ViewController, the small title will continue to display for a second when moving from the detail ViewController to the previous ViewController via the UINavigationBar back button.

Use willMove(toParent:) function to change the title back before the segue is performed.

Swift 4

override func willMove(toParent parent: UIViewController?) {
    navigationItem.largeTitleDisplayMode = .always
    navigationController?.navigationBar.prefersLargeTitles = true
}

Solution 5:[5]

    if #available(iOS 11.0, *) {
        self.navigationItem.largeTitleDisplayMode = UINavigationItem.LargeTitleDisplayMode.never
    } else {
        // Fallback on earlier versions
    }

Solution 6:[6]

It might be very late but this could be useful for someone..

include the below code on your detail view controller under viewDidLoad

navigationItem.largeTitleDisplayMode = .never

Solution 7:[7]

SwiftUI:

step 1. Use ZStack step 2 : .navigationBarTitle("", displayMode: .inline)

Solution 8:[8]

I had the same issue and needed to place a NavigationItem on the second ViewController's storyboard. My NavigationItem was being created automatically by the segue and its prefersLargeTitle in the viewDidLoad() was not finished loading before the view appeared. Adding a NavigationItem to the storyboard fixed this issue and allowed me to set the prefersLargeTitle in the storyboard's properties menu.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VojtaStavik
Solution 2
Solution 3 Edouard Barbier
Solution 4 Aaron
Solution 5 Codetard
Solution 6
Solution 7 MVZ
Solution 8 Ben Hardin