如何在iOS 11中换行大标题?

Col*_*mab 5 title navbar swift ios11 xcode9

我正在尝试使用Swift在iOS 11中使用新的大型标题系统。当标题过长时(请参见图像示例),它会添加...而不是换行或缩小文本大小。如何添加换行符?

具有长标题的示例图像

这是我用来设置标题的一些代码:

self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationController?.navigationBar.largeTitleTextAttributes = [NSForegroundColorAttributeName: MyGlobalVariable.themeMainColor]
self.navigationController?.navigationBar.largeTitleTextAttributes = [NSFontAttributeName: UIFont.systemFont(ofSize: 22)]
navigationItem.title = "Search by Name"
Run Code Online (Sandbox Code Playgroud)

小智 3

尝试这个:

for navItem in (self.navigationController?.navigationBar.subviews)! {
    for itemSubView in navItem.subviews {
        if let largeLabel = itemSubView as? UILabel {
            largeLabel.text = self.title
            largeLabel.numberOfLines = 0
            largeLabel.lineBreakMode = .byWordWrapping
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这对我有用。

在此输入图像描述