mrs.tat
mrs.tat

Reputation: 697

Display button only when specific child is selected

I'm using XLPagerTabStrip in my app to display three different children.. this is working perfectly.

  import UIKit
import XLPagerTabStrip

class AccountViewController: ButtonBarPagerTabStripViewController {


override func viewDidLoad() {

    self.settings.style.buttonBarBackgroundColor = .white
    self.settings.style.buttonBarItemBackgroundColor = .white
    self.settings.style.selectedBarBackgroundColor = UIColor(red:0.52, green:0.77, blue:0.33, alpha:1.0)
    self.settings.style.buttonBarItemFont = .boldSystemFont(ofSize: 13)
    self.settings.style.selectedBarHeight = 2.0
    self.settings.style.buttonBarMinimumLineSpacing = 10
    self.settings.style.buttonBarItemTitleColor = .black
    self.settings.style.buttonBarItemsShouldFillAvailableWidth = true
    self.settings.style.buttonBarLeftContentInset = 0
    self.settings.style.buttonBarRightContentInset = 0
    self.settings.style.selectedBarHeight = 4.0

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

    super.viewDidLoad()

    let orginalimg = UIImage(named: "Arrow Left")
    let tinitimg = orginalimg?.withRenderingMode(.alwaysTemplate)
    backbtn.setImage(tinitimg, for: UIControlState.normal)
    backbtn.tintColor = UIColor(red:0.16, green:0.27, blue:0.60, alpha:1.0)

}

@IBOutlet weak var backbtn: UIButton!
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBOutlet weak var addnewadd: UIButton!
@IBAction func addnewadd(_ sender: Any) {
    performSegue(withIdentifier: "addsegue", sender: self)
}

override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {

    let child1 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "account")
    let child2 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "password")
    let child3 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "address")
    return [child1,child2,child3]
}
}

the problem is that I want to show the 'addnewadd' button (which is hidden) when the second tab is selected.

I tried this:

   override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {

    if toIndex == 2 {

        self.addnewadd.isHidden = false

        }
    else{
        self.addnewadd.isHidden = true
    }
   }

this works but the tab won't change when swiped to another child it will always stay selected on the first tab ...

how can I solve this?

Upvotes: 1

Views: 263

Answers (0)

Related Questions