swift - 使用外观代理的全局更改 UINavigationBar 背景不起作用
问题描述
我正在尝试使用 UINavigationBarAppearance 更改我的应用程序中所有 UINavigationBars 的一些属性。我application(_:didFinishLaunchingWithOptions:)
在 AppDelegate.swift 中调用以下函数:
func customizeAppearance() {
let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.configureWithDefaultBackground()
navBarAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
navBarAppearance.backgroundColor = UIColor.black
UITabBar.appearance().backgroundColor = UIColor.black
let tintColor = UIColor(red: 255/255.0, green: 238/255.0, blue: 136/255.0, alpha: 1.0)
UITabBar.appearance().tintColor = tintColor
}
我希望这会改变标题文本的背景颜色和颜色,但是当我运行应用程序时,只有文本颜色会改变(UITabBar 也是如此)。有什么建议么?
解决方案
你应该UINavigationBarAppearance
在你的 UINavigationControllers 中使用它。如果你使用 UINavigationController 的全局外观,你应该使用UINavigationBar.appearance()
而不是UINavigationBarAppearance()
.
推荐阅读
- jquery - Jquery html() 不能工作不止一次
- android - Android 应用程序和 amazon s3 存储桶之间的实时文件同步
- android - 如何从 ArrayList 中获取特定元素?
- c++ - C++:同一范围内的多个 MPI_Recv
- jquery - 用 Jasmine 测试 jQuery 点击事件
- android - RecyclerView - 如何使用?
- django - socket.gaierror: [Errno 11004] getaddrinfo failed,django
- mysql - 带有 IF 语句的 MySQL 触发器
- asp.net-web-api - 在 Android 上使用 Restsharp 连接到 localhost
- racket - 分别计算每个子列表的匹配数