更改 UITabBar 中的项目颜色 iOS
Change item color in UITabBar iOS
我的应用程序有一个标签栏,如下所示:
Tab Bar 必须是绿色的,正如您所看到的,Tab Bar 中项目的图标有点难看。如何更改此选项卡栏中图标的颜色?我必须使用标准的标签栏。
谢谢
试试这个
[[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 *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);
我建议将 UITabbar 的背景更改为一些较深的颜色,而不是绿色。只需为未选中的选项卡保留默认的灰色(Apple 蒙版为灰色)。使用下面的片段设置选定的选项卡掩码颜色。
[[UITabBar外观] setTintColor:[UIColor redColor]];
这将避免最终用户混淆选项卡处于选中状态还是未选中状态。
我的应用程序有一个标签栏,如下所示:
Tab Bar 必须是绿色的,正如您所看到的,Tab Bar 中项目的图标有点难看。如何更改此选项卡栏中图标的颜色?我必须使用标准的标签栏。 谢谢
试试这个
[[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 *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);
我建议将 UITabbar 的背景更改为一些较深的颜色,而不是绿色。只需为未选中的选项卡保留默认的灰色(Apple 蒙版为灰色)。使用下面的片段设置选定的选项卡掩码颜色。
[[UITabBar外观] setTintColor:[UIColor redColor]];
这将避免最终用户混淆选项卡处于选中状态还是未选中状态。