Xcode 13编译项目 iOS15适配 UINavigationBar和UITabBar设置无效,变成黑色

1.今天更新了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
    }

你可能感兴趣的:(iOS开发,iOS15,Xcode,13,导航栏,UINavigationBar,导航栏黑色)