uitabbarcontrolleruitabbarxcode7.2swift5tvos9.1

How to change tab bar item text colour on focus in TVOS


enter image description here

I have four item in tab bar.

1> Watch. (Black Colour)

2> On Demand. (Black Colour)

3> Search. (Black Colour)

4> Settings. (My Colour)

How can i change the colour of item text in tab bar to match with its icon colour. (Right now Performance is selected in the tab bar)

enter image description here

How can I change the color of "1,2,3" text in tabbar to match with its icon color. (Right now Performance is selected in the tab bar)

I tried to set TitleTextAttributes.

UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0),NSFontAttributeName: UIFont(name: "SFUIDisplay-Regular", size: 36.0)!], forState:UIControlState.Normal)
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor(red: 22.0/255.0, green: 209.0/255.0, blue: 237.0/255.0, alpha: 1.0),NSFontAttributeName: UIFont(name: "SFUIDisplay-Regular", size: 36.0)!], forState:UIControlState.Focused)

But i want to like it.

enter image description here

This issue got in the tvos 9.1.


Solution

  • I'm not sure if I understood your question but I faced some similar issue when developing an Apple TV app.

    What I wanted to do is to change the font color for the tab bar items.

    This is what I ended doing. First I made a UITabBarController subclass and liked it to their controller on the storyboard. Then I added this code in the -(void)viewDidLoad

    for(UITabBarItem * item in self.tabBar.items) {
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor darkGrayColor]} forState:UIControlStateNormal];
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blueColor]} forState:UIControlStateFocused];
    }
    

    And everything works pretty well.

    Hope it helps!