iosswiftxlpagertabstrip

XLPagerTabStrip - How do I change the selected bar color as the selection changes


I'm trying to do a design a XLPagerTabStrip control where the overall theme changes as the tabs change.

The following is what's getting called when a tab changes

changeCurrentIndexProgressive = { [weak self] (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
        guard changeCurrentIndex == true else { return }
        oldCell?.label.textColor = .black
        newCell?.label.textColor = UIColor.red

        //Change the navigation bar's color
        self?.navigationController?.navigationBar.barTintColor = UIColor.red

        //Attempting to change the selected bar color
        self?.settings.style.selectedBarBackgroundColor = UIColor.green       
   }

Changing the navigation controllers color works, but I can't get the the selected bar (or any thing under the settings object) to change from within here?

Is it possible to change the settings once the view has been loaded?


Solution

  • Code Check

    if you check the code Code Search for selectedBarBackgroundColor then you find this 3 interesting search results:

    BaseButtonBarPagerTabStripViewController#viewDidLoad

    buttonBarView.selectedBar.backgroundColor = settings.style.selectedBarBackgroundColor
    

    BarPagerTabStripViewController#viewDidLoad

    barView.selectedBar.backgroundColor = settings.style.selectedBarBackgroundColor ?? barView.selectedBar.backgroundColor
    

    ButtonBarPagerTabStripViewController#viewDidLoad

    buttonBarView.selectedBar.backgroundColor = settings.style.selectedBarBackgroundColor
    

    that means that you need to set the BackgroundColor before an viewDidLoad.

    Issue

    see also the answer of this issue: XLPagerTabStrip Issue #137:

    Actually this isnot a issue. Settings should be configured before viewDidLoad is called. Could you please document it in the readme?

    workaround

    buttonBarView is a public var maybe you can set it additional to the settings direct this property: buttonBarView.selectedBar.backgroundColor