我正在尝试使用 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"
最佳答案
试试这个:
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
}
}
}
它对我有用。
关于swift - 如何在 iOS 11 中换行较长的大标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46438881/