iOS 11 下如何为不同 UIViewController 设置开关 LargeTitles

iOS 11 为 UINavigationController 引入了一个 LargeTitles 的效果,可以通过在 UINavigationController 上设置 prefersLargeTitles = true 的形式开启。那么如何设置只为其中一个 UIViewController 开启大标题效果,而为其他的 UIViewController 关闭大标题效果呢?

很简单,只要记住,UINavigationController 只有一个 UINavigationBar,但子 UIViewController 每个都有各自的 UINavigationItem 来控制具体的效果。

通过设置 UIViewController 的 UINavigationItem 的 largeTitleDisplayMode,可以达到精准控制大标题效果:

  • automatic:上一个 Controller 是什么效果,当前 Controller 就是什么效果;
  • always:不管上一个 Controller 是什么效果,当前 Controller 始终是大标题效果;
  • never:不管上一个 Controller 是什么效果,当前 Controller 始终不是大标题效果。

欢迎使用图拉鼎开发的产品

Manico - 快速启动和切换 App

高效率 App 启动与切换工具,使用它将加倍电脑日常使用的效率,免费下载体验。

1 Comment

NB 把所有细节都罗列的这么详细

Leave a Comment