我在我的应用中添加了tabbar
。我一次显示5个标签。我正在尝试制作标签栏的自定义颜色。我在TabBarController
UITabBarItem *homeTab = [self.exposeTabBar.items objectAtIndex:0];
UIImage *home_unselectedImage = [UIImage imageNamed:@"home.png"];
UIImage *home_selectedImage = [UIImage imageNamed:@"home.png"];
[homeTab setImage: [home_unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[homeTab setSelectedImage: home_selectedImage];
UITabBarItem *bookmarkTab = [self.exposeTabBar.items objectAtIndex:1];
UIImage *bookmark_unselectedImage_ = [UIImage imageNamed:@"bookmark.png"];
UIImage *bookmark_selectedImage = [UIImage imageNamed:@"bookmark.png"];
[bookmarkTab setImage: [bookmark_unselectedImage_ imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[bookmarkTab setSelectedImage: bookmark_selectedImage];
UITabBarItem *postTab = [self.exposeTabBar.items objectAtIndex:2];
UIImage *post_unselectedImage_ = [UIImage imageNamed:@"create-post.png"];
UIImage *post_selectedImage = [UIImage imageNamed:@"create-post_white.png"];
[postTab setImage: [post_unselectedImage_ imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[postTab setSelectedImage: post_selectedImage];
UITabBarItem *notificationTab = [self.exposeTabBar.items objectAtIndex:3];
UIImage *notification_unselectedImage_ = [UIImage imageNamed:@"notifications.png"];
UIImage *notification_selectedImage = [UIImage imageNamed:@"notifications_white.png"];
[notificationTab setImage: [notification_unselectedImage_ imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[notificationTab setSelectedImage: notification_selectedImage];
UITabBarItem *profileTab = [self.exposeTabBar.items objectAtIndex:4];
UIImage *profile_unselectedImage_ = [UIImage imageNamed:@"user-profile.png"];
UIImage *profile_selectedImage = [UIImage imageNamed:@"user-profile_white.png"];
[profileTab setImage: [profile_unselectedImage_ imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[profileTab setSelectedImage: profile_selectedImage];
对于未选择的图像,它显示的是正确的图像,但对于所选的图像,它没有显示正确的图像。它显示图标的蓝色图像。
请告诉我该如何防止这种情况?
答案 0 :(得分:3)
在app delegate:
中尝试使用带有清晰颜色的标签栏外观api方法[[UITabBar appearance] setTintColor:[UIColor clearColor]];
答案 1 :(得分:0)
尝试更改 tabBar颜色和 tabBar色调 例如:
// Generate a black tab bar
self.tabBarController.tabBar.barTintColor = [UIColor blackColor];
// Set the selected icons and text tint color
self.tabBarController.tabBar.tintColor = [UIColor orangeColor];
答案 2 :(得分:0)
尝试更改tabBarController的“tabEdgeColor”和“topEdgeColor”。
或者更改tabBar的barTint或色调颜色以清除颜色。
答案 3 :(得分:0)
对于选定的图像,您还应该设置渲染模式,试试这个:
[homeTab setSelectedImage:[home_selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
答案 4 :(得分:0)
您可以将自定义图像用于不同的颜色
tabBarItem1.image = [[UIImage imageNamed:"imag"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem1.selectedImage = [[UIImage imageNamed:@"selected_image"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];