Pau*_* T. 3 xcode uibarbuttonitem ios uiappearance swift
更新
我想更改导航栏中后退按钮中的箭头和文本之间的偏移量。在我设置之前它工作得很好
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)
Run Code Online (Sandbox Code Playgroud)
UINavigationBar.appearance()当指定时会覆盖所有内容并且对所有内容都有自己的设置,因此您需要通过其自己的属性配置偏移量,例如
...
standardAppearance.backButtonAppearance.normal.titlePositionAdjustment =
UIOffset(horizontal: -20, vertical: 0)
appearance.standardAppearance = standardAppearance
...
Run Code Online (Sandbox Code Playgroud)
UIBarButtonItem.appearance()所以不需要的部分- 只需将其删除
| 归档时间: |
|
| 查看次数: |
1219 次 |
| 最近记录: |