iOS11AdaptationTips icon indicating copy to clipboard operation
iOS11AdaptationTips copied to clipboard

Use the increased navigation-bar title in iOS 11

Open ChenYilong opened this issue 8 years ago • 2 comments

Q:

iOS 11 Beta 1 uses the increased navigation-bar title for almost all system-apps (it started doing this in iOS 10 and the Music app). What is the public API for this coming in iOS 11.

The behavior is that the title has an increased font-size, is left aligned and will move to the navigation-bar once the user scrolls down. I've attached some screens showing this behavior in the Messages app

image1 image2
here enter image description here

A:

UINavigationBar has a prefersLargeTitles: Bool property. Docs here.

class UINavigationBar {
   var prefersLargeTitles: Bool
}

UINavigationItem has a largeTitleDisplayMode: UINavigationItem.LargeTitleDisplayMode property. Docs here.

class UINavigationItem {
   var largeTitleDisplayMode: LargeTitleDisplayMode
}

Both of these can be modified in the Interface Builder.

To turn on this behavior set navigationController.navigationBar.prefersLargeTitles to true. Then you can control each individual view controller in the navigation controller stack by setting navigationItem.largeTitleDisplayMode.

The general design guidelines by Apple are that large titles shouldn't be used everywhere (for example, the Clock app does not use them), and it's generally preferred that only the first level of the navigation controller uses the large titles. However, these are just general guidelines.

It's introduced in What's New in Cocoa Touch video.

Reference: Use the increased navigation-bar title in iOS 11

ChenYilong avatar Jun 09 '17 05:06 ChenYilong

我这边想做一个类似iOS11设置界面中同效果的一个navbar+搜索框的效果。请问您是否知道iOS11设置界面中navbar+搜索框的处理方案。 我这边想出了两套方案: 1、直接加到导航栏中了。我原本以为会像LargeTitles一样有系统提供对应的api或者其他处理方案,但是在iOS11的文档中没有找到相应的处理方法。 2、另一种方案是将搜索框加入到tableview的headerview中,这样的话貌似需要处理一些联动效果,以及将原始导航条下方的线条隐藏并且还要加入到headerview中,感觉处理起来挺麻烦的。 请问您是否知道有好的处理方案建议或者是否有了解到iOS11中提供了对应的处理方案。如果有的话,请多多指导。非常感谢。

EchoZuo avatar Aug 29 '17 09:08 EchoZuo

您好,问题已经解决,已经找到了iOS11对应的设置属性了。

UINavigationItem.h
navigationItem.searchController  //iOS 11 新增属性
navigationItem.hidesSearchBarWhenScrolling //决定滑动的时候是否隐藏搜索框;iOS 11 新增属性

因为是在UINavigationItem.h中的属性,我之前一直在UINavigationBar.h和UINavigationController.h中寻找相关属性,所以没找到。是自己太不仔细了。

EchoZuo avatar Aug 29 '17 09:08 EchoZuo