UITabBar displays UITabBarItem image ignoring rendering mode AlwaysOriginal

你。 提交于 2019-12-05 02:36:55

问题


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.

Here is the same code running on tvOS 9.0

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?


回答1:


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)



回答2:


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




回答3:


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




回答4:


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)
        }


来源:https://stackoverflow.com/questions/34186287/uitabbar-displays-uitabbaritem-image-ignoring-rendering-mode-alwaysoriginal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!