xmartlabs / XLPagerTabStrip

Android PagerTabStrip for iOS.
MIT License
6.97k stars 1.32k forks source link

Change buttonBarView colors after viewDidLoad #815

Closed grantespo closed 3 years ago

grantespo commented 3 years ago

Hello, I've been using this library successfully for quite sometime.

I usually setup by buttonBarView by calling this code before viewDidLoad()

        settings.style.buttonBarItemBackgroundColor = DynamicColor.dynamicBackgroundColor2.themeColor
        settings.style.selectedBarBackgroundColor = DynamicColor.selectedMenuColor.themeColor
        settings.style.buttonBarItemTitleColor = DynamicColor.unselectedMenuColor.themeColor
        settings.style.buttonBarItemFont = .boldSystemFont(ofSize: 14)
        settings.style.selectedBarHeight = 2.0
        settings.style.buttonBarMinimumLineSpacing = 0
        settings.style.buttonBarItemsShouldFillAvailableWidth = true
        settings.style.buttonBarLeftContentInset = 0
        settings.style.buttonBarRightContentInset = 0

        changeCurrentIndexProgressive = { (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
            guard changeCurrentIndex == true else { return }
            oldCell?.label.textColor = DynamicColor.unselectedMenuColor.themeColor
            newCell?.label.textColor = DynamicColor.selectedMenuColor.themeColor
        }
        buttonBarView.contentOffset = CGPoint(x: 0, y: 0)

This code works great. Howver, in my app, users can choose whether they want dark mode or light mode in the app settings.

So, is it possible to change buttonBarView's colors after viewDidLoad? Or am I forced to re-instantiate the entire viewController?

grantespo commented 3 years ago

Looks like the only way to achieve this was to naturally re-call viewDidLoad by re-instantiate the vc.

Ex; the vc was a child viewcontroller, so I did this

myVC.removeFromParent()
myVC = storyboard?.instantiateViewController(identifier: "MyVC") as? MyVC
addChild(myVC)