更新
我想在导航栏中的后退按钮中更改箭头和文本之间的偏移量。直到我设置好,它才能正常工作
UINavigationBar.appearance().standardAppearance = newAppearance
这里是完整的代码:
let appearance = UINavigationBar.appearance()
let standardAppearance = UINavigationBarAppearance()
standardAppearance.configureWithOpaqueBackground()
standardAppearance.backgroundColor = someColor
standardAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: titleColor]
standardAppearance.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: titleColor]
standardAppearance.shadowColor = navigationShadowColor
// if remove theses 2 line, offset code works!!!
appearance.standardAppearance = standardAppearance
appearance.scrollEdgeAppearance = standardAppearance
// code to set offset
UIBarButtonItem
.appearance()
.setBackButtonTitlePositionAdjustment(
UIOffset(horizontal: -20, vertical: 0),
for: .default)
已更新,我想在导航栏中的后退按钮中更改箭头和文本之间的偏移量。在我设置UINavigationBar.appearance()。standardAppearance = newAppearance之前,它工作正常,这是...
您需要在应用程序委托方法“ didFinishLaunchingWithOptions”中设置TitlePositionAdjustment,然后它将起作用。
这是我的自定义后退按钮代码
提及的setBackButtonTitlePositionAdjustment
外观修改仅适用于标准高度的导航栏,因此由于激活了大标题导航栏模式(即UINavigationBar.prefersLargeTitles
),因此可能无法使用。