仅在选择特定孩子时显示按钮

时间:2018-05-03 07:46:42

标签: ios swift xcode xlpagertabstrip

我在我的应用程序中使用XLPagerTabStrip显示三个不同的孩子..这是完美的。

  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]
}
}

问题是我想在选择第二个标签时显示'addnewadd'按钮(隐藏)。

我试过了:

   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
    }
   }

这样可行,但是当滑动到另一个孩子时,标签不会改变,它将始终在第一个标签上保持选中状态...

我该如何解决这个问题?

0 个答案:

没有答案