iOS 15 navigationBar、tabBar颜色变黑的问题

iOS 15中导航栏出现如下情况:

image.png

storyboard按下图设置

image.png

或者在 UINavigationController中加入如下代码即可

// navigationBar
if #available(iOS 13.0, *) {
    let appearance = UINavigationBarAppearance()
    appearance.configureWithOpaqueBackground()
    appearance.backgroundColor = NorMal_Color
    appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
    navigationBar.standardAppearance = appearance
    navigationBar.scrollEdgeAppearance = navigationBar.standardAppearance
} else {
    UINavigationBar.appearance().barTintColor = NorMal_Color
    UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.white]
    UINavigationBar.appearance().tintColor = .white
}

tababriOS 15中出现下图情况

image.png

storyboard中如下图设置即可

image.png

也可用代码实现:

// tabBar
if #available(iOS 13.0, *) {
    let itemAppearance = UITabBarItemAppearance()
    itemAppearance.normal.titleTextAttributes = [.foregroundColor: NorMal_Color ?? .green]
    itemAppearance.selected.titleTextAttributes = [.foregroundColor: Selected_Color ?? .orange]
    
    let appearance = UITabBarAppearance()
    appearance.stackedLayoutAppearance = itemAppearance
    appearance.configureWithOpaqueBackground()
    appearance.backgroundColor = .white
    tabBarController?.tabBar.standardAppearance = appearance
    if #available(iOS 15.0, *) {
        tabBarController?.tabBar.scrollEdgeAppearance = tabBarController?.tabBar.standardAppearance
    } else {
        // Fallback on earlier versions
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容