iOS15适配 UINavigationBar和UITabBar设置无效,变成黑色

今天更新了xcode13,运行项目发现iOS15以上的手机导航栏和状态栏之前设置的颜色等属性都不起作用了,都变成了黑色,滚动的时候才能变成正常的颜色,经确认得用UINavigationBarAppearance和UITabBarAppearance这两个属性对导航栏和状态栏设置才能生效。以下是示例代码(仅是背景颜色),具体属性根据自己实际情况进行设置

    if (@available(iOS 15.0, *)) {
        UINavigationBarAppearance * bar = [UINavigationBarAppearance new];
        bar.backgroundColor = [UIColor blueColor];
        bar.backgroundEffect = nil;
        self.navigationController.navigationBar.scrollEdgeAppearance = bar;
        self.navigationController.navigationBar.standardAppearance = bar;
        
        UITabBarAppearance * bar2 = [UITabBarAppearance new];
        bar2.backgroundColor = [UIColor whiteColor];
        bar2.backgroundEffect = nil;
        self.tabBarController.tabBar.scrollEdgeAppearance = bar2;
        self.tabBarController.tabBar.standardAppearance = bar2;
    } else {
        // Fallback on earlier versions
    }


版权声明:本文为CSDN博主「奋斗吧灬青年」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/ljc_563812704/article/details/120419430

你可能感兴趣的:(iOS15适配 UINavigationBar和UITabBar设置无效,变成黑色)