在Interface Builder中自定义UINavigationBar
(特别是自定义栏的barTintColor
和标题文本颜色)在iOS 13中似乎变得非常棘手。
以下是我尝试在Interface Builder中进行操作的视频:https://youtu.be/fQPjKv0yrk8
长话短说,如果同时设置导航栏的barTintColor
和标题文本颜色(大或常规标题),则标题颜色将被忽略。
使用超类UIView
的backgroundColor
似乎也很麻烦。关于如何定制导航栏,是否有明确的答案?还是它们只是变成了越野车,需要hacky解决方案?
更新:这似乎在Xcode 11.4中是个问题,据说在Xcode 11.4.1中已解决:
[Xcode 11.4.1 Release Notes的引用:
接口生成器修复了导致使用Xcode 11.4生成时在情节提要和XIB文档中设置的某些UINavigationBar外观属性被忽略的问题。 (60883063)(FB7639654)
但是,对于我来说似乎还没有解决,我描述的问题仍然在我身上发生。
navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.red]
navigationController?.navigationBar.barTintColor = .yellow
并且在大标题的情况下,将
titleTextAttributes替换为largeTitleTextAttributes