大导航栏自定义高度

Large navigation bar custom height

是否可以更改大导航栏的高度?

self.navigationItem.largeTitleDisplayMode = .always 
self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationController?.navigationBar.addSubview(expandedNavBar)

由于 Apple HIG,我认为您不能更改导航栏的高度。如果你想改变 navigationBar 的高度,你可以删除 navigationBar 并且你可以像 navigationBar

一样向用户展示你自己的自定义视图

如果你想让navigationBar大一点,你可以试试这个技巧,在提示中添加一个空字符串属性。

self.navigationItem.prompt = ""

好的,我是这样找到的:

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.minimumLineHeight = 200
let attributes: [NSAttributedString.Key: Any] = [ .paragraphStyle: paragraphStyle]

let navigationBar = navigationController?.navigationBar
if #available(iOS 15, *) {
    if let appearance = navigationBar?.standardAppearance {
        appearance.largeTitleTextAttributes = attributes
        navigationBar?.standardAppearance = appearance
        navigationBar?.scrollEdgeAppearance = appearance
    }
} else {
    navigationBar?.largeTitleTextAttributes = attributes
}