我已经在互联网上进行了彻底搜索,无法找到如何调整navigationItem.title出现的高度。我指的是显示在导航栏中间的标题。
答案 0 :(得分:1)
答案 1 :(得分:0)
Tomas ”答案是最简单的答案。除此之外,您可以使用自定义titleView
。这样,您可以水平和垂直插入文本:
class TitleView: UIView {
private let label: UILabel = {
let label = UILabel()
label.font = UIFont.boldSystemFont(ofSize: 15)
return label
}()
var title: String? {
get { return label.text }
set { label.text = newValue }
}
convenience init(title: String, inset: UIEdgeInsets) {
self.init()
label.text = title
addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false
label.topAnchor.constraint(equalTo: topAnchor, constant: inset.top).isActive = true
label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: inset.left).isActive = true
bottomAnchor.constraint(equalTo: label.bottomAnchor, constant: inset.bottom).isActive = true
trailingAnchor.constraint(equalTo: label.trailingAnchor, constant: inset.right).isActive = true
}
}
然后您可以像这样简单地使用它:
let titleView = TitleView(title: "TitleView", inset: .init(top: -10, left: 0, bottom: 0, right: 0))
vc.navigationItem.titleView = titleView