[英]iOS 15 How to change tab bar item text color programmatically
我的應用程序使用標簽欄控制器構建,我為選定的和普通的標簽欄提供了自定義顏色,它在 iOS 14 中運行良好,但在 iOS 15 中它無法正常運行。
這是我的參考代碼,我嘗試了很多方法,但沒有任何幫助。
func updateTabBarItemFont() {
self.tabBar.tintColor = UIColor.tabBarForegroundActive
self.tabBar.barTintColor = UIColor.white
self.tabBar.isTranslucent = false
let textStyle = TextStyle.tabBarHeader
let normal = [NSAttributedString.Key.font: textStyle.font, NSAttributedString.Key.foregroundColor: UIColor.neutralForegroundNormal]
UITabBarItem.appearance().setTitleTextAttributes(normal, for: .normal)
let selected = [NSAttributedString.Key.font: textStyle.font, NSAttributedString.Key.foregroundColor: UIColor.tabBarForegroundActive]
UITabBarItem.appearance().setTitleTextAttributes(selected, for: .selected)
}
我期待與 iOS 15 中的 iOS 14 文本顏色相同
提前致謝!!!
tabBar.scrollEdgeAppearance
是 iOS 15 上必須設置的新 API,設置相同的外觀
設置標准外觀后在底部添加以下行
tabBarController?.tabBar.scrollEdgeAppearance = tabBarController?.tabBar.standardAppearance
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.