问题描述
iOS 11 Beta 1几乎为所有系统应用程序使用增加的导航栏标题(它开始在iOS 10和音乐应用程序中执行此操作)。我想知道Apple是否有iOS 11的公共API,或者它是否会暂时保密。
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). I am wondering if Apple has a public API for this coming in iOS 11, or whether it will stay private for now.
行为是标题的字体大小增加,左对齐并在用户向下滚动时移动到导航栏。我已在消息应用附加了一些显示此行为的屏幕。
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 here.
虽然到目前为止我在 UINavigationController
和 UINavigationBar
中找不到任何引用,也许有人知道更多细节!
Although I could not find any reference in the UINavigationController
and UINavigationBar
so far, maybe someone knows some more details!
推荐答案
对 UINavigationBar
iOS 11的API仅为 prefersLargetitles
。查看
The only change done to UINavigationBar
API for iOS 11 is prefersLargetitles
only. check here
您可以通过一个小的更改对自己的应用程序执行此操作:在IB中为您的导航栏选择首选大标题,或者如果您希望在代码中使用
You can do it to your own apps with one small change: check "Prefers Large Titles" for your navigation bar in IB, or if you prefer to do it in code using
navigationController?.navigationBar.prefersLargeTitles = true
编辑
如果您需要更改大标题的文本属性,则需要使用新的 largeTitleTextAttributes
上的属性UINavigationBar
:
If you need to change the text attributes of the large title you need to use the new largeTitleTextAttributes
property on UINavigationBar
:
UINavigationBar.appearance().largeTitleTextAttributes = [
NSForegroundColorAttributeName: UIColor.white
]
Swift 4.2的更新:
As NSForegroundColorAttributeName
已重命名为 NSAttributedString.Key.foregroundColor
,使用:
Update for Swift 4.2:
As NSForegroundColorAttributeName
has been renamed to NSAttributedString.Key.foregroundColor
, use:
UINavigationBar.appearance().largeTitleTextAttributes = [
NSAttributedString.Key.foregroundColor: UIColor.black
]
这篇关于使用iOS 11中增加的导航栏标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!