UITabBar displays UITabBarItem image ignoring rend

2020-06-23 09:42发布

With the release of tvOS 9.1 and Xcode 7.2, my UITabBarItem images are being displayed incorrectly. In my view controllers, I set the tabBarItem.image and tabBarItem.selectedImage with images using UIImageRenderingMode.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)
}

The selected image displays correctly, but the non-selected image displays as a template, that is, its color information is ignored.

Both images displayed correctly using the tvOS 9.0 SDK, but the non-selected image is displaying incorrectly in tvOS 9.1. To make matters worse, the non-selected images are being shown as black and the tab bar background is also black.

enter image description here

Here is the same code running on tvOS 9.0

enter image description here

I suspect this is a bug with tvOS 9.1, but has anyone found a workaround or see something that I am not doing correctly?

4条回答
看我几分像从前
2楼-- · 2020-06-23 09:51

This is was confirmed as a bug by Apple and has been fixed in tvOS 9.1.1.

查看更多
欢心
3楼-- · 2020-06-23 10:08

It may be help to tvOS 9.1. This code write into the viewDidLoad() of UITabBarController.

for item in self.tabBar.items!{
            item.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.blackColor()], forState: UIControlState.Normal)
            item.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.greenColor()], forState: UIControlState.Focused)
        }
查看更多
兄弟一词,经得起流年.
4楼-- · 2020-06-23 10:12

It appears to definitely be a bug in the UITabBarController implementation for tvOS 9.1. So I ended up writing my own replacement. While at it, I added support for more than 7 tab bar items, made it look nice on a black background, and included a search bar on one of the tabs (also on a black background). This solves many of the difficulties I faced trying to build my first tvOS app.

Link to Github repository

enter image description here

查看更多
Evening l夕情丶
5楼-- · 2020-06-23 10:14

We have seen something similar in our tvos app, except we use text instead of images. tvOS 9.1 ignoring textColor.

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

UITabBarItem.appearance().setTitleTextAttributes([
    NSForegroundColorAttributeName: <barTextColorSelected>,
], forState: UIControlState.Selected)
查看更多
登录 后发表回答