UITabBar显示UITabBarItem图像,忽略渲染模式AlwaysOriginal

时间:2015-12-09 18:25:15

标签: xcode uitabbar tvos tvos9.1

随着tvOS 9.1和Xcode 7.2的发布,我的UITabBarItem图像显示不正确。在我的视图控制器中,我使用tabBarItem.imagetabBarItem.selectedImageUIImageRenderingMode.AlwaysOriginal设置为图像。

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)

    self.tabBarItem.image = UIImage(named: "myTabImage")?.imageWithRenderingMode(.AlwaysOriginal)
    self.tabBarItem.selectedImage = UIImage(named: "myTabImageSelected")?.imageWithRenderingMode(.AlwaysOriginal)
}

所选图像显示正确,但未选中的图像显示为模板,即忽略其颜色信息。

使用tvOS 9.0 SDK正确显示两个图像,但未选中的图像在tvOS 9.1中显示不正确。更糟糕的是,未选择的图像显示为黑色,标签栏背景也显示为黑色。

enter image description here

这是在tvOS 9.0上运行的相同代码

enter image description here

我怀疑这是tvOS 9.1的一个错误,但有没有人找到解决方法或看到我做得不对的东西?

4 个答案:

答案 0 :(得分:1)

我们在tvos应用程序中看到类似的东西,除了我们使用文本而不是图像。 tvOS 9.1忽略textColor。

UITabBarItem.appearance().setTitleTextAttributes([
    NSForegroundColorAttributeName: <barTextColor>
], forState: UIControlState.Normal)

UITabBarItem.appearance().setTitleTextAttributes([
    NSForegroundColorAttributeName: <barTextColorSelected>,
], forState: UIControlState.Selected)

答案 1 :(得分:1)

它似乎肯定是tvOS 9.1的UITabBarController实现中的一个错误。所以我最后写了自己的替代品。在此期间,我添加了对超过7个标签栏项目的支持,使其在黑色背景上看起来很漂亮,并在其中一个选项卡上包含搜索栏(也在黑色背景上)。这解决了我在尝试构建我的第一个tvOS应用程序时遇到的许多困难。

Link to Github repository

enter image description here

答案 2 :(得分:0)

这被Apple确认为一个错误,并已在tvOS 9.1.1中修复。

答案 3 :(得分:0)

它可能对tvOS 9.1有所帮助。此代码会写入viewDidLoad()的{​​{1}}。

UITabBarController