A-A+

iOS15解决导航条适配问题

博客主机

在旧版本代码中设置导航条颜色使用的是navigationBar.barTintColor,但在iOS15上并没有生效,而且navigationBar.isTranslucent=NO也没有生效,导航条依然是透明的。

解决方案:

if (@available(iOS 15.0, *)) {
UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];

[appearance configureWithOpaqueBackground]

;
//设置导航条背景色
appearance.backgroundColor = UIColor.whiteColor;
//设置导航条标题颜色
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];

[attributes setValue:UIColor.blackColor forKey:NSForegroundColorAttributeName]

;
appearance.titleTextAttributes = attributes;

[UINavigationBar appearance].standardAppearance = appearance;
[UINavigationBar appearance].scrollEdgeAppearance = appearance;

}
[UINavigationBar appearance].backgroundColor = UIColor.whiteColor;
[UINavigationBar appearance].barTintColor = UIColor.whiteColor;
[UINavigationBar appearance].titleColor = UIColor.blackColor;
同理可以设置tabbar的颜色

if (@available(iOS 15.0, *)) {
UITabBarAppearance * appearance = [[UITabBarAppearance alloc] init];

[appearance configureWithOpaqueBackground]

;
appearance.backgroundColor = UIColor.whiteColor;
[UITabBar appearance].scrollEdgeAppearance = appearance;
[UITabBar appearance].standardAppearance = appearance;
}
[UITabBar appearance].backgroundColor = UIColor.whiteColor;

————————————————
版权声明:本文为CSDN博主「培根芝士」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/watson2017/article/details/120435763

给我留言

Copyright © ios教程,苹果粉丝,苹果资讯,ios入门教程,ios学习,ios程序员,ios视频教程,ios粉丝网 保留所有权利.   Theme  Ality

用户登录