CosmicMind / Material

A UI/UX framework for creating beautiful applications.
http://cosmicmind.com
MIT License
11.99k stars 1.26k forks source link

TabsController - tabItem state colors issues #915

Closed markst closed 7 years ago

markst commented 7 years ago

As mentioned here: https://github.com/CosmicMind/Material/issues/860#issuecomment-337090396

Previously I was able to set the states for tabItem's 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 since the introduction of https://github.com/CosmicMind/Material/releases/tag/2.12.0 I am no longer able to set the highlight state of my tab bar items.

This goes beyond where by I was previously able to update tab bar state individually such as:

func updateTabBarItem() {
    // If test is a failure:
    if let status = self.test?.testStatus, [TestStatus.failedUnknown.rawValue,
                                            TestStatus.failedBattery.rawValue,
                                            TestStatus.failedLamp.rawValue,
                                            TestStatus.failedControl.rawValue].contains(status) {

        self.tabItem.titleColor = UIColor.cs_Thunderbird()
        self.tabItem.setTitleColor(UIColor.cs_Thunderbird(), for: .selected)
        self.tabBarItem.title = "Test & Status •"
    } else {
        self.tabItem.titleColor = UIColor.cs_Thunder()
        self.tabItem.setTitleColor(UIColor.cs_Citron(), for: .selected)
        self.tabBarItem.title = "Test & Status"
    }
}

This would enable different button states based on their selection. Producing appearance such as: example

markst commented 7 years ago

In conjunction with the following code:

extension FittingViewController: TabsControllerDelegate {

    fileprivate func updatePaddleColour(selected index: Int) {
        if let status = self.testResultViewController?.test?.testStatus {
            if [TestStatus.failedUnknown.rawValue,
                TestStatus.failedBattery.rawValue,
                TestStatus.failedLamp.rawValue,
                TestStatus.failedControl.rawValue].contains(status) {

                if index == 1 {
                    self.pageController?.tabBar.lineColor = UIColor.cs_Thunderbird()
                } else {
                    self.pageController?.tabBar.lineColor = UIColor.cs_Citron()
                }
            } else {
                self.pageController?.tabBar.lineColor = UIColor.cs_Citron()
            }
        }
    }

    // MARK: - TabsControllerDelegate

    func tabsController(tabsController: TabsController, didSelect viewController: UIViewController) {
        let selectedIndex = tabsController.viewControllers.index(of: viewController)!
        self.updatePaddleColour(selected: selectedIndex)
    }
}
markst commented 7 years ago

@danieldahan I prefer the previous setup. Perhaps it's worth discussing with @OrkhanAlikhanov as to workarounds?

daniel-jonathan commented 7 years ago

I reopened the issue #860. So I will close this as they are now linked.

OrkhanAlikhanov commented 7 years ago

@markst I haven't updated to the latest Material yet. I still have some pods that don't support swift 4.