iOS15解决导航条适配问题

iOS15解决导航条适配问题,第1张

在旧版本代码中设置导航条颜色使用的是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;

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/996712.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存