TabBarItem图标不会立即出现在ios 8中

前端之家收集整理的这篇文章主要介绍了TabBarItem图标不会立即出现在ios 8中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有tabBarItem icon的问题.这是我的故事板的一部分的屏幕截图.

有一个基本的viewController与一些按钮.当其中一个按钮被触摸时,会出现一个带有三个标签的tabBarController.在iOS 8中,tabBarItems的图标最初不会出现.如果我更改了视图控制器,则会出现上一个和当前视图控制器的两个图标.如果我选​​择第三个选项卡,然后出现tabBarItems的所有图标.这是我的问题的屏幕截图:

TabBarController的第一个外观:

如果我改变标签

这是我用来将tabBarItems的图标(所有图标都是30×30)设置为TabBarController的第一个viewController的viewDidLoad方法代码

[[[self.tabBarController.viewControllers objectAtIndex:0] tabBarItem]  setFinishedSelectedImage:[UIImage imageNamed:@"1d1.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"1b1.png"]];

[[[self.tabBarController.viewControllers objectAtIndex:1] tabBarItem]  setFinishedSelectedImage:[UIImage imageNamed:@"2d1.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"2b1.png"]];

[[[self.tabBarController.viewControllers objectAtIndex:2] tabBarItem]  setFinishedSelectedImage:[UIImage imageNamed:@"3d1.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"3b1.png"]];

以下是适用于iOS 7的屏幕截图:

谁能帮我这个??

解决方法

经过几个小时的搜索和阅读不同的答案,包括@ Zala的答案,这部分代码进入了TabBarController的第一个viewController的viewDidLoad,并最终起作用.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{

    UITabBarItem *tabBarItem = [self.tabBarController.tabBar.items objectAtIndex:0];

    UIImage *unselectedImage = [UIImage imageNamed:@"1b1.png"];
    UIImage *selectedImage = [UIImage imageNamed:@"1d1.png"];

    [tabBarItem setImage: [unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [tabBarItem setSelectedImage:[selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];


    UITabBarItem *tabBarItem1 = [self.tabBarController.tabBar.items objectAtIndex:1];

    UIImage *unselectedImage1 = [UIImage imageNamed:@"2b1.png"];
    UIImage *selectedImage1 = [UIImage imageNamed:@"2d1.png"];

    [tabBarItem1 setImage: [unselectedImage1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [tabBarItem1 setSelectedImage: [selectedImage1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

    UITabBarItem *tabBarItem2 = [self.tabBarController.tabBar.items objectAtIndex:2];

    UIImage *unselectedImage2 = [UIImage imageNamed:@"3b1.png"];
    UIImage *selectedImage2 = [UIImage imageNamed:@"3d1.png"];

    [tabBarItem2 setImage: [unselectedImage2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [tabBarItem2 setSelectedImage:[selectedImage2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];


    [tabBarItem setTitle:@"Φωτογραφίες"];

    [tabBarItem2 setTitle:@"360° Φωτογραφία"];

    [tabBarItem1 setTitle:@"Βίντεο"];



}
else
{


    [[[self.tabBarController.viewControllers objectAtIndex:0] tabBarItem]  setFinishedSelectedImage:[UIImage imageNamed:@"1d1.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"1b1.png"]];


    [[[self.tabBarController.viewControllers objectAtIndex:1] tabBarItem]  setFinishedSelectedImage:[UIImage imageNamed:@"2d1.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"2b1.png"]];
    [[[self.tabBarController.viewControllers objectAtIndex:2] tabBarItem]  setFinishedSelectedImage:[UIImage imageNamed:@"3d1.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"3b1.png"]];

    [[[self.tabBarController.viewControllers objectAtIndex:0] tabBarItem] setTitle:@"Φωτογραφίες"];

    [[[self.tabBarController.viewControllers objectAtIndex:2] tabBarItem] setTitle:@"360° Φωτογραφία"];

    [[[self.tabBarController.viewControllers objectAtIndex:1] tabBarItem] setTitle:@"Βίντεο"];



}
原文链接:https://www.f2er.com/iOS/331090.html

猜你在找的iOS相关文章