Aymen HARRATH
Aymen HARRATH

Reputation: 494

selected and focused states of UITabBarItem on tvOS

How can I give tabBar items different titles colors for selected and focused states?

I am setting title text attributes but it does not make any difference between selected and focused states, I have always the same color.

Here is how I create tabBar Items:

   for title in titlesArray {

        let item = UITabBarItem(title: title, image: nil, selectedImage: nil)
        item.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor(white: 1, alpha: 1)], for: .selected)
        item.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor(white: 1, alpha: 0.2)], for: .normal)
        item.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.blue], for: .focused)

        tabBarItems.append(item)
    }

    tabbar.items = tabBarItems

Can any one help me to understand how to achieve this. Thanks.

Upvotes: 0

Views: 439

Answers (1)

Amit
Amit

Reputation: 4896

Try this if it can help in anyway :

For normal:

 UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.grayColor()], forState:.Normal)

and for selected :

   UITabBarItem.appearance().setTitleTextAttribute([NSForegroundColorAttributeName:UIColor.redColor()], forState:.Selected)

Upvotes: 1

Related Questions