您当前的位置: 首页 >  ios

培根芝士

暂无认证

  • 0浏览

    0关注

    446博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

iOS15解决导航条适配问题

培根芝士 发布时间:2021-09-23 15:26:52 ,浏览量:0

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

关注
打赏
1660824269
查看更多评论
立即登录/注册

微信扫码登录

0.0358s