更改UITabBar项目的自定义图像 我使用过这段代码,但它没有用。
UIImage *selectedImage0 = [UIImage imageNamed:@"f.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"f.png"];
UIImage *selectedImage1 = [UIImage imageNamed:@"g.png"];
UIImage *unselectedImage1 = [UIImage imageNamed:@"g.png"];
UIImage *selectedImage2 = [UIImage imageNamed:@"i.png"];
UIImage *unselectedImage2 = [UIImage imageNamed:@"i.png"];
UIImage *selectedImage3 = [UIImage imageNamed:@"s.png"];
UIImage *unselectedImage3 = [UIImage imageNamed:@"s.png"];
UIImage *selectedImage4 = [UIImage imageNamed:@"t.png"];
UIImage *unselectedImage4 = [UIImage imageNamed:@"t.png"];
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
UITabBarItem *item4 = [tabBar.items objectAtIndex:4];
[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
[item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
[item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
[item3 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3];
[item4 setFinishedSelectedImage:selectedImage4 withFinishedUnselectedImage:unselectedImage4];
答案 0 :(得分:4)
您应该使用下面的- (UIImage *)imageWithRenderingMode:(UIImageRenderingMode)renderingMode NS_AVAILABLE_IOS(7_0);
方法
item0.image = [unselectedImage1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item0.selectedImage = [selectedImage1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
答案 1 :(得分:0)
您已为每个tabitem简单图像和悬停图像设置了两个图像。
item0.image = [[UIImage imageNamed:@"f.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; // set simple image
item0.selectedImage = [[UIImage imageNamed:@"f.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; // set hover image