![](/img/trans.png)
[英]Storyboard Global Tint UITabBar Tint changed in IOS 7.1
[英]UITabBar tintColor is not changed storyboard
我已經設置了全局 tintColor,我可以在界面構建器中看到它,當我選擇 UITabBar 和 UITabBarController 時,仍然當我運行應用程序時,所選 UITabBarItem 的色調是 iOS 默認的(藍色),而不是我的有設置。 我錯過了什么?
PS UITabBarController 被推送到 navigationController,它不是 rootViewController
在didFinishLaunchingWithOptions:
方法中使用此代碼appDelegate
[[UITabBar appearance] setSelectedImageTintColor: [UIColor redColor]];
用你想要的顏色替換紅色。
如果您的目標是 iOS 8,那么
在 iOS 8 中不推薦使用 selectedImageTintColor 使用 tintColor
迅速
UITabBar.appearance().tintColor = UIColor.redColor()
目標c
[[UITabBar appearance] setTintColor: [UIColor redColor]];
在我的應用程序中,我希望每個 ViewController 在呈現時都具有唯一的 TabBarItem 顏色。
在 iOS 8 中,在故事板中手動添加 tintColor 屬性工作正常,但在 iOS 9 / Xcode 8 下不再有任何影響。
我通過在每個 TabBarController 的子視圖控制器中包含以下代碼解決了這個問題,覆蓋了它們的每個 ViewDidAppear() 函數。
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.tabBarController?.tabBar.tintColor = UIColor.whateverColor
//The rest of your code
}
這在任何 ViewController 中都是安全的,因為 ? 在 tabBarController 調用之后。 如果 ViewController 沒有嵌入在 TabBarController 中,則整行都會被忽略。
通過將此代碼放在每個 VC 中,您可以輕松指定每個 TabBarItem 的顏色。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.