0

我用largeTitleBar. 当navigationBar.title字符超过 20 个字节时(以 iPhone SE 为例),backButtonItem.title消失。(如果是 iPhoneX,22 字节)

navigationBar.title变得截断会影响这个问题。但我没有任何想法来解决这个问题。

navigationItem.title = someText
// when navigationItem.title is truncated, backButtonItem.title disappears.
4

1 回答 1

0
self.title = "Your TiTle Text"
var lbl = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
lbl.text = navigationItem?.title
lbl.textColor = UIColor.white
if let fontSize = UIFont(name: "Helvetica-Bold", size: 30.0) {
    lbl.font = fontSize
}
lbl.backgroundColor = UIColor.clear
lbl.adjustsFontSizeToFitWidth = true
lbl.textAlignment = .center
navigationItem?.titleView = lbl

试试上面的代码可能会对你有所帮助。

于 2018-03-21T10:10:16.823 回答