在iOS 11之前,为了制作一个自定义标签,我做了如下操作:

let titleLabel = UILabel(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 40))
titleLabel.text = self.customTitleText
titleLabel.backgroundColor = .clear
titleLabel.textAlignment = .left
titleLabel.textColor = .white
titleLabel.font = UIFont.boldSystemFont(ofSize: 17)
titleLabel.adjustsFontSizeToFitWidth = true
titleLabel.minimumScaleFactor = 0.25
navigationItem.titleView = titleLabel

现在,titleView似乎并不影响大标题。如何在iOS 11中实现文本收缩?

最佳答案

你可以这样使用:

self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationController?.navigationBar.largeTitleTextAttributes = [
        NSAttributedStringKey.foregroundColor: UIColor.red,
        NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 17)
    ]

关于ios - 缩小UINavigationBar大标题文本的大小,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46375720/

10-11 10:37