ios - 在 Xcode 13 [[UINavigationBar 外观] setBarTintColor: 无法正常工作?
问题描述
我已将我的 Xcode 更新为 13,后来在我的旧项目导航和标签栏颜色中的文字更改为透明。
我的代码是
[[UINavigationBar appearance] setBarTintColor:[UIColor AppThemeColour]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTranslucent:NO];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
我尝试添加背景颜色,但导航栏的标题和图像没有出现。
self.navigationController.navigationBar.backgroundColor = [UIColor bOneAppThemeColor];
[[UINavigationBar appearance] setBarTintColor:[UIColor AppThemeColour]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTranslucent:NO];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
我已经研究了下面的链接,但我无法在 Objective C 中实现它
解决方案
您所做的几乎所有事情都是错误的(并且已经错了好几年)。您需要使用 UINavigationBarAppearance (和 UITabBarAppearance)并将它们应用于 barstandardAppearance
和它的scrollEdgeAppearance
. 设置外观的背景颜色,而不是它的色调颜色。并且永远不要触摸该translucent
物业。
在这个简单的示例中,我们让所有导航栏都采用您的主题颜色。修改以满足您的需求和愿望:
if (@available(iOS 13.0, *)) {
UINavigationBarAppearance* appear = [UINavigationBarAppearance new];
appear.backgroundColor = [UIColor AppThemeColor];
id proxy = [UINavigationBar appearance];
[proxy setStandardAppearance: appear];
[proxy setScrollEdgeAppearance: appear];
} else {
// Fallback on earlier versions
}
推荐阅读
- r - 如何使用 Plotly 可视化正态分布图?
- android - 裁剪图像并将其上传到服务器
- json - 无法从 API 访问特定 JSON 数据
- excel - 是否可以在 Excel VBA 中将函数或子函数作为参数传递?
- c# - 在实体框架中使用没有主键的只读表
- python-3.x - 如何轻松解析内容?
- swift - Swift Bond 框架 - 多对一关系 - 如果有任何变化,则触发单个命令
- google-cloud-platform - 如何从 GCS 列出和下载元数据
- user-interface - Flutter UI 挂在异步操作上
- python - range(1,n+2) 没有在 for 循环中打印我想要的输出