Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 319
A Tyshka Avatar asked Dec 20 '17 14:12

A Tyshka


3 Answers

it's very simple.

In your DetailView you should set navigationItem.largeTitleDisplayMode to .never

(not navigationController?.navigationItem.largeTitleDisplayMode !!)

navigationItem.largeTitleDisplayMode = .never
like image 121
Alexander Spirichev Avatar answered Sep 17 '22 12:09

Alexander Spirichev


SwiftUI version

.navigationBarTitle("Title", displayMode: .inline)
like image 27
VojtaStavik Avatar answered Sep 19 '22 12:09

VojtaStavik


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
like image 43
Krunal Avatar answered Sep 21 '22 12:09

Krunal