How to hide elements in a Stack View

Noah Iarrobino picture Noah Iarrobino · Aug 13, 2018 · Viewed 9.4k times · Source

I have 4 separate views and I want to hide the other 3 of them when one of the buttons is pressed.

I have them in a UIStackView but .isHidden = true does not hide the views for some reason.

It works fine when they're not in a stack view.

@IBAction func qbpressed(_ sender: Any) {
    QBContainer.isHidden = false
    WRContainer.isHidden = true
    RBContainer.isHidden = true
    QBIndicator.isHidden = false
    WRIndicator.isHidden = true
    RBIndicator.isHidden = true
    TEIndicator.isHidden = true
    QBButton.setTitleColor(#colorLiteral(red: 0, green: 0.5008062124, blue: 1, alpha: 1), for: .normal)
    WRButton.setTitleColor(#colorLiteral(red: 0.7540688515, green: 0.7540867925, blue: 0.7540771365, alpha: 1), for: .normal)
    RBButton.setTitleColor(#colorLiteral(red: 0.7540688515, green: 0.7540867925, blue: 0.7540771365, alpha: 1), for: .normal)
    TEButton.setTitleColor(#colorLiteral(red: 0.7540688515, green: 0.7540867925, blue: 0.7540771365, alpha: 1), for: .normal)

    if intersitial.isReady{
        intersitial.present(fromRootViewController: self)
    } 
}

stack view

Answer

Noah Iarrobino picture Noah Iarrobino · Aug 14, 2018

isHidden property doesn't work, but you can use alpha and achieve the same result,

QBIndicator.alpha = 1.0 will work for QBIndicator.isHidden = false and QBIndicator.alpha = 0.0 will work for QBIndicator.isHidden = true