iOS 15 navigationBar、tabBar顏色變黑的問(wèn)題

iOS 15中導(dǎo)航欄出現(xiàn)如下情況:

image.png

storyboard按下圖設(shè)置

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中出現(xiàn)下圖情況

image.png

storyboard中如下圖設(shè)置即可

image.png

也可用代碼實(shí)現(xiàn):

// 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
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容