iOS8似乎发生了一些变化,现在我的标签栏图标都没有正确显示。大多数情况下,在标签处于活动状态之前,它们不会显示:
但有时他们根本没有露面,只给我一个大蓝盒子(就像我解雇一个覆盖整个窗户的景色一样):
这是我在iOS8之前所做的:
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"paintbrush-white.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"paintbrush-black.png"]];
tabBarItem1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
tabBarItem1.title = @"";
答案 0 :(得分:1)
如上所述,如果你看看:
您会注意到此方法已弃用,请尝试更改:
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"paintbrush-white.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"paintbrush-black.png"]];
为:
[tabBarItem1 setImage:[[UIImage imageNamed:@"paintbrush-white.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem1 setSelectedImage:[[UIImage imageNamed:@"paintbrush-black.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
您可能还会遇到图像尺寸问题,具体取决于在iPhone 5屏幕和iPhone 2屏幕上测试@ 2x图像时的图像尺寸
答案 1 :(得分:0)
您是否尝试过setSelectedImage:?
UIImage * image = [UIImage imageNamed:@“img.png”] [tabItem setSelectedImage:image];
这对我有用。
答案 2 :(得分:-1)
此方法在iOS 8中已弃用:
Use initWithTitle:image:selectedImage: or the image and selectedImage properties along with UIImageRenderingModeAlwaysOriginal