Material: TabsController - tabItem colors for states.

Created on 8 Sep 2017  路  10Comments  路  Source: CosmicMind/Material

By the way, I was using the tabBar delegate to change title colors for (de)selected states accordingly.

func tabBar(tabBar: TabBar, willSelect tabItem: TabItem) {
    tabBar.tabItems.forEach {
        $0.titleColor = .darkGray
    }    
    tabItem.titleColor = App.colors.primary
}

Shouldn't be there something like selectedTabItemTitleColor and normalTabItemTitleColor. ?
image

enhancement feature request

Most helpful comment

I can add this with the delegation calls.

All 10 comments

I can add this with the delegation calls.

+100

i do this on viewdidload

Please find this feature available in the latest Material 2.12.0 release.

Example:

tabBar.setColor(Color.grey.base, for: .normal)
tabBar.setColor(Color.blue.base, for: .selected)

Thank you @mohpor for the initial version, it really helped with laying down the groundwork :)

@danieldahan I think TabItemState is unnecessary - why not just use the UIControlState enum?

Previously I would setup colours as follows:

override func prepare() {
    super.prepare()

    // Setup tab bar items appearance:
    self.viewControllers.forEach { (vc) in
        vc.tabItem.titleLabel?.font = UIFont.sparkyFont(.calibri, weight: .bold, size: 14)
        vc.tabItem.setTitleColor(UIColor.cs_Thunder(),for: .normal)
        vc.tabItem.setTitleColor(UIColor.cs_Citron(), for: .highlighted)
        vc.tabItem.setTitleColor(UIColor.cs_Citron(), for: .selected)
    }
}

However, now updateColors() overrides all of this & I don't have support for .highlighted state.

@markst yeah, we can make that adjustment.

@markst I opted out of using UIControlState as it has more states than necessary for managing the tab items. That said, the latest interface for colors looks like this:

tabBar.setLineColor(Color.orange.base, for: .selected)

tabBar.setTabItemsColor(Color.grey.base, for: .normal)
tabBar.setTabItemsColor(Color.purple.base, for: .selected)
tabBar.setTabItemsColor(Color.green.base, for: .highlighted)

This is available in Material 2.12.2.

@danieldahan Thank you!

Was this page helpful?
0 / 5 - 0 ratings