UITabBarItem icon not colored correctly for iOS 13 when a bar tint color is specified in Interface Builder in Xcode 11, beta 2

后端 未结 6 1994
闹比i
闹比i 2020-12-11 15:47

I have a problem with the color of my UITabBarItems when I run on iOS 13 simulators, using Xcode 11, beta 2. I have made a sample project from scratch, and everything works

相关标签:
6条回答
  • 2020-12-11 16:10

    For Objective C you can use in AppDelegate:

    [[UITabBar appearance] setTintColor:[UIColor whiteColor]];
    [[UITabBar appearance] setUnselectedItemTintColor:[UIColor colorWithRed:255.0f/255.0f green:255.0f/255.0f blue:255.0f/255.0f alpha:0.65f]];
    
    0 讨论(0)
  • 2020-12-11 16:11

    Use the attribute field "Image Tint" in IB.

    Use the attribute field "Image Tint" in IB

    0 讨论(0)
  • 2020-12-11 16:18

    There is a new appearance API in iOS 13. To color tabbar item's icon and text correctly using Xcode 11.0 you can use it like this:

        if #available(iOS 13, *) {
            let appearance = UITabBarAppearance()
    
            appearance.backgroundColor = .white
            appearance.shadowImage = UIImage()
            appearance.shadowColor = .white
    
            appearance.stackedLayoutAppearance.normal.iconColor = .black
            appearance.stackedLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
            appearance.stackedLayoutAppearance.normal.badgeBackgroundColor = .blue
    
            appearance.stackedLayoutAppearance.selected.iconColor = .red
            appearance.stackedLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red]
    
            self.tabBar.standardAppearance = appearance
    
        } 
    
    0 讨论(0)
  • 2020-12-11 16:21

    On the surface, this might seem like a bug, however you can mitigate it by defining an .unselectedItemTintColor on your UITabBar instance.

    self.tabBar.unselectedItemTintColor = [UIColor lightGrayColor];
    
    0 讨论(0)
  • 2020-12-11 16:26
    self.tabBarController?.tabBar.unselectedItemTintColor = UIColor.lightGray
    

    This works for me in swift 4. Just put this in the override func viewWillDisappear(_ animated: Bool) method and this will update as the view is changing.

    So it will look something like this

    override func viewWillDisappear(_ animated: Bool) {
        self.tabBarController?.tabBar.unselectedItemTintColor = UIColor.lightGray
    }
    

    Even if this is a bug(I'm not sure) you can use this to change the color of the tab bar item by using any color of you choice

    0 讨论(0)
  • 2020-12-11 16:29
        if #available(iOS 13.0, *) {
            let appearance = tabBar.standardAppearance
            appearance.stackedLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
            appearance.stackedLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.blue]
            appearance.stackedLayoutAppearance.normal.iconColor = UIColor.black
            appearance.stackedLayoutAppearance.selected.iconColor = UIColor.blue
            tabBar.standardAppearance = appearance
        } else {
            tabBar.unselectedItemTintColor = UIColor.black
            tabBar.tintColor = UIColor.blue
        }
    
    0 讨论(0)
提交回复
热议问题