【问题标题】:Issue creating a large title navigation bar with 2 lines | Swift 5创建带有 2 行的大标题导航栏的问题 |斯威夫特 5
【发布时间】:2021-05-16 19:51:41
【问题描述】:

基本上我想为 iOS 14 创建一个双行大标题导航栏 - 我似乎无法在任何地方找到确定的答案。

以下是我目前拥有的:

title = "Good Morning \nTim"

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 uinavigationcontroller uikit uinavigationbar ios14


【解决方案1】:

例如,您的 ViewController 需要在 viewDidLoad 中进行此修改:

let label = UILabel()
label.numberOfLines = 2
label.textAlignment = .center
label.text = "Good Morning \nTim"
navigationItem.titleView = label

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 2017-03-24
    • 1970-01-01
    • 1970-01-01
    • 2015-08-02
    相关资源
    最近更新 更多