【问题标题】:UITabBar acts strange in iOS 7, how to fix it?UITabBar 在 iOS 7 中表现异常,如何解决?
【发布时间】:2013-09-27 14:30:41
【问题描述】:
[[UITabBar appearance] setTintColor:[UIColor redColor]]; // for unselected items that are red
[[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]]; // for selected items that are green

为什么这段代码在 iOS 7 中不起作用?

setTintColor 有效,但仅更改“选定”图标的颜色,而不是像早期 iOS 版本中那样更改未选定的颜色,这很奇怪吗? setSelectedImageTintColor 根本不起作用?真的不能随意给图标上色了吗?

另外,setSelectionIndicatorImage 在应用启动时没有按预期工作,iOS 7 中发生了什么?

Derp herp Apple,为什么?

【问题讨论】:

    标签: ios uitabbarcontroller uitabbar ios7 uitabbaritem


    【解决方案1】:
    for (int i=0; i (smallerthen)arrayOfTabBarItems.count; i++) {
    
        NSString *unselectedImageName = [NSString stringWithFormat:@"%@.png", arrayOfTabBarItems[i]];
    
        NSString *selectedImageName = [NSString stringWithFormat:@"%@-pressed.png", arrayOfTabBarItems[i]];
    
        [tabBarCtrl.tabBar.items[i] setFinishedSelectedImage:[UIImage imageNamed:selectedImageName] withFinishedUnselectedImage:[UIImage imageNamed:unselectedImageName]];
    }
    

    这对我有用。

    【讨论】:

      【解决方案2】:

      Adam Waite 的回答无效。 iOS7下的setFinishedSelectedImage方法忽略了选中的图片。你需要这样:

      UITabBarItem *item1 = _tabBarController.tabBar.items[0];
      item1.image = [[UIImage imageNamed:@"item1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
      item1.selectedImage = [UIImage imageNamed:@"item1-selected"];
      

      【讨论】:

        【解决方案3】:

        这不是色调,但你可以用图像来做到这一点:

        [self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"item_seleted.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"item_unselected.png"]];

        【讨论】:

        • 我还需要做其他事情吗?未选中的对我来说工作正常,但选中的总是显示为蓝色或标签栏 tinctColor 的颜色
        【解决方案4】:

        这是 iOS 7 中的一个已知问题。tintColor 用于选定的选项卡图像。 selectedImageTintColor 被完全忽略。无法为未选择的标签图像着色。

        请参阅 Apple 开发者论坛 https://devforums.apple.com/message/851126#851126 上关于此的讨论。

        【讨论】:

          【解决方案5】:

          从 iOS 7 开始,您必须使用 setBarTintColor: 设置背景颜色,setTintColor: 现在影响前景色。

          【讨论】:

          • setBarTintColor 没有任何改变,已经尝试过了。这很奇怪而且搞砸了:(
          • 你有没有试过直接在标签栏的实例上设置barTintColor,而不是UIAppearance代理?我在使用-setBarTintColor: 时没有遇到过这个问题。
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2021-11-07
          • 2017-09-15
          • 2017-09-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多