gpt4 book ai didi

swift - 如何在 iOS 11 中换行较长的大标题?

转载 作者:搜寻专家 更新时间:2023-10-31 08:04:02 24 4
gpt4 key购买 nike

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

Example image with long title

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

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
}
}
}

它对我有用。

enter image description here

关于swift - 如何在 iOS 11 中换行较长的大标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46438881/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com