Use the enlarged name of the navigation bar in iOS 11

iOS 11 Beta 1 uses the enlarged title bar of the navigation bar for almost all system applications (it started to do this in iOS 10 and the Music app). I am wondering if Apple has a public API for this in iOS 11, or while it remains closed.

The behavior is that the title has an increased font size, is left-justified and moves to the navigation bar after the user scrolls down. I have attached several screens showing this behavior in the Messages application here:

enter image description here

Although I still haven't found links to the UINavigationController and UINavigationBar , maybe someone knows some details!

+53
ios iphone ios11 uinavigationbar xcode9-beta
Jun 07 '17 at 9:49 on
source share
6 answers

The only change, prefersLargetitles in the UINavigationBar API for iOS 11, is prefersLargetitles only for prefersLargetitles . check here

You can do this for your own applications with one small change: check the “Prefers big headers” box for the navigation bar in IB or, if you prefer to do this in code, using

 navigationController?.navigationBar.prefersLargeTitles = true 

edit

If you need to change the text attributes of a large header, you need to use the new largeTitleTextAttributes property on the UINavigationBar :

 UINavigationBar.appearance().largeTitleTextAttributes = [ NSForegroundColorAttributeName: UIColor.white ] 

Update for Swift 4.2:

Since NSForegroundColorAttributeName been renamed to NSAttributedString.Key.foregroundColor , use:

  UINavigationBar.appearance().largeTitleTextAttributes = [ NSAttributedString.Key.foregroundColor: UIColor.black ] 
+103
Jun 07 '17 at 10:38 on
source share

UINavigationBar has the prefersLargeTitles: Bool property. The docs are here .

 class UINavigationBar { var prefersLargeTitles: Bool } 

UINavigationItem has the largeTitleDisplayMode: UINavigationItem.LargeTitleDisplayMode property largeTitleDisplayMode: UINavigationItem.LargeTitleDisplayMode . The docs are here .

 class UINavigationItem { var largeTitleDisplayMode: LargeTitleDisplayMode } 

Both of them can be changed in Interface Builder.

To enable this behavior, set navigationController.navigationBar.prefersLargeTitles to true . You can then control each individual view controller in the navigation controller stack by setting navigationItem.largeTitleDisplayMode .

Apple's general design principles are that large headers should not be used everywhere (for example, the Clock application does not use them), and they usually prefer that only the first level of the navigation controller use large headers. However, these are just general recommendations.

Whats new in Cocoa Touch video (7:37).

+10
Jun 09 '17 at 1:45
source share

Just check “Prefers large headers” in the attribute inspector of the navigation bar.

enter image description here

+6
Dec 25 '17 at 15:06
source share
 if #available(iOS 11.0, *) { self.navigationController?.navigationBar.prefersLargeTitles = true self.navigationItem.largeTitleDisplayMode = .always } else { // Fallback on earlier versions } 

Please note that there are some bugs in the beta version that cause a large header to appear when viewed manually.

+5
Jun 19 '17 at 10:19 on
source share
 if #available(iOS 11.0, *) { navigationController?.navigationBar.prefersLargeTitles = true navigationController?.navigationBar.topItem?.title = "Hello" navigationController?.navigationItem.largeTitleDisplayMode = .automatic let attributes = [ NSAttributedStringKey.foregroundColor : UIColor.red, ] navigationController?.navigationBar.largeTitleTextAttributes = attributes } else { // Fallback on earlier versions } 
+5
Sep 21 '17 at 17:34 on
source share

Since large headers are available starting with iOS 11, you should also check the iOS version:

  if #available(iOS 11.0, *) { navigationController?.navigationBar.prefersLargeTitles = true } 
0
Jul 03 '19 at 7:28
source share



All Articles