簡體   English   中英

選擇后如何顯示不同的標簽欄圖標顏色

[英]How have different tab bar icon color when selected

我想知道是否有一種方法可以為UITabBarController選擇的不同圖標提供不同的顏色,我知道:

[[UITabBar appearance] setTintColor:[UIColor whiteColor]];

我可以更改所有圖標的選擇顏色,但是如何為其他選項卡呢?

一種方法是簡單地更改不同視圖控制器中標簽欄的顏色。

假設您有3個不同的標簽: tab1tab2tab3 ,它們都顯示不同的viewcontrollers。 現在,假設您要在tab1使用藍色,但在tab2tab3使用紅色。 然后,您可以簡單地viewWillAppear:下行添加到不同ViewControllersviewWillAppear:方法。

對於第一個viewController(顯示在tab1 ,您將具有:

//In your viewcontroller which is shown in tab1
- (void)viewWillAppear:(BOOL)animated {
   [super viewWillAppear:animated];
   // change tint color to blue
   [self.tabBarController.tabBar setTintColor:[UIColor blueColor]];
}

對於其他兩個,您只需放置另一種顏色:

//In your viewcontrollers which are shown in tab2 and tab3
- (void)viewWillAppear:(BOOL)animated {
   [super viewWillAppear:animated];
   // change tint color to red
   [self.tabBarController.tabBar setTintColor:[UIColor redColor]];
}

就這么簡單。 當然,還有其他方法可以做到這一點,但是這一方法非常干凈直接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM