缩小UINaviationBar大标题文本的大小

问题描述 投票:1回答:1

在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中实现文本缩小?

ios swift uinavigationbar ios11
1个回答
0
投票

你可以像这样使用:

self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationController?.navigationBar.largeTitleTextAttributes = [
        NSAttributedStringKey.foregroundColor: UIColor.red,
        NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 17)
    ]
© www.soinside.com 2019 - 2024. All rights reserved.