【发布时间】:2022-09-23 11:10:50
【问题描述】:
我有一个像这样的自定义 UINavigationController:
class CustomNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
delegate = self
setupDefaultAppearance()
}
private func setupDefaultAppearance() {
UINavigationBar.appearance().tintColor = R.color.textBlack()
let titleAttributes: [NSAttributedString.Key: Any] = [ .font: R.font.interMedium(size: 18)! ]
UINavigationBar.appearance().titleTextAttributes = titleAttributes
// Hide the title in bar button items
let backButtonAttributes: [NSAttributedString.Key: Any] = [ .font: UIFont(name: \"Helvetica-Bold\", size: 0.1)!,
.foregroundColor: UIColor.clear]
UIBarButtonItem.appearance().setTitleTextAttributes(backButtonAttributes, for: .normal)
UIBarButtonItem.appearance().setTitleTextAttributes(backButtonAttributes, for: .highlighted)
}
}
但是,隐藏栏按钮项目中的标题的代码搞砸了 IQKeyboardManager。因此,键盘或任何选择器视图中的 Done 按钮(或工具栏上的任何按钮)现在都消失了。所以,我相信我不应该使用 UIBarButtonItem.appearance() 静态函数。如何删除导航控制器的后退按钮的标题而不在键盘和选择器视图中产生错误?
谢谢。
标签: ios swift uinavigationcontroller uikit