[英]Change item color in UITabBar iOS
我的應用程序具有一個標簽欄,如下所示:
標簽欄必須為綠色,並且您可以在標簽欄中看到該項目的圖標,這有點難以看清。 如何更改此選項卡欄中圖標的顏色? 我必須使用標准的標簽欄。 謝謝
可以使用以下代碼來代替使用圖標,而使用圖標圖像
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
tabBarItem1.selectedImage = [[UIImage imageNamed:@"selectedImage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem1.image = [[UIImage imageNamed:@"unselectedImage.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem1.imageInsets= UIEdgeInsetsMake(6, 0, -6, 0);
嘗試這個
[[self tabBar] setSelectedImageTintColor:[UIColor greenColor]];
或這個
[UITabBarItem.appearance setTitleTextAttributes:@{
UITextAttributeTextColor : [UIColor greenColor] } forState:UIControlStateNormal];
[UITabBarItem.appearance setTitleTextAttributes:@{
UITextAttributeTextColor : [UIColor purpleColor] } forState:UIControlStateSelected];
或這個
[[self tabBar] setTintColor:[UIColor redColor]];
或這個
[UITabBarItem.appearance setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor greenColor]} forState:UIControlStateNormal];
[UITabBarItem.appearance setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor purpleColor]} forState:UIControlStateSelected];
嘗試這個
[[UITabBar appearance] setTintColor:[UIColor redColor]];
[[UITabBar appearance] setBarTintColor:[UIColor yellowColor]];
// set tabbar background image
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tabbar_bg"]];
// remove shadow image of tabbar
[[UITabBar appearance] setShadowImage:[[UIImage alloc]init]];
我建議將UITabbar的背景更改為較深的顏色,而不是綠色。 只需為未選中的選項卡保留默認的灰色(Apple遮罩為灰色)即可。 在下方使用以下內容設置所選標簽的遮罩顏色。
[[UITabBar外觀] setTintColor:[UIColor redColor]];
這樣可以避免最終用戶混淆選項卡是處於選中狀態還是處於未選中狀態。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.