iOS 11中导航栏中的大型标题的多行

时间:2017-10-05 05:43:06

标签: ios uinavigationbar ios11

iOS 11中导航栏的新大标题是否可以显示多行? App Store应用程序执行此操作但我在当前文档中找不到任何内容来执行此操作。标准行为只显示一行带省略号,如果它太长。

enter image description here

1 个答案:

答案 0 :(得分:4)

将以下代码添加到viewWillAppear:

    navigationController?.navigationBar.prefersLargeTitles = true
    self.navigationController?.navigationItem.largeTitleDisplayMode = .automatic

    self.title = "Hello big text, For navigation large style bar"
    navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.black, NSAttributedStringKey.font : UIFont.preferredFont(forTextStyle: .largeTitle)]

    var count = 0
    for item in(self.navigationController?.navigationBar.subviews)! {
        for sub in item.subviews{
            if sub is UILabel{
                if count == 1 {
                    break;
                }
                let titleLab :UILabel = sub as! UILabel
                titleLab.numberOfLines = 0
                titleLab.text = self.title
                titleLab.lineBreakMode = .byWordWrapping
                count = count + 1
            }
        }

    }
    self.navigationController?.navigationBar.layoutSubviews()
    self.navigationController?.navigationBar.layoutIfNeeded()

面对后退按钮的问题很快就会更新..