How to use one button to show/ hide another button

I would like Button to show/ hide button b every time it is pressed. So if pressed it either makes the button appear or disappear picture is attached.

  1. Connect buttons to code
  • You will need to set up both IBAction’s and IBOutlets
  1. UIButton like many objects have a property that is called “isHidden” which is set to ‘false’ by default and you can set it to ‘true’ through code.
  2. When you tap button the IBAction func code that corresponding to the respective button will be called with your desired actions

EX:
@IBOutlet weak var button: UIButton!
@IBOutlet weak var buttonB: UIButton!

@IBAction func button( sender: UIButton ) // When button is tapped this code is called
{
buttonB.isHidden = true // Access isHidden Property - Set it to true to hide the button
}

@IBAction func buttonB( sender: UIButton )
{

}

Challenge for you is how to logically hide and unhide the buttonB :slight_smile: Happy coding

How can I make a if else statement on this. If the button is hidden hitting the button will make it a appear and vice versa. This is what I tried swift is telling my I am missing an if condition.

    @IBAction func aa(sender: AnyObject) {
    
    if {b.hidden = true}
    else{b.hidden = false}
    
}

by default isHidden will be true so you access the isHidden property in an if statement to check the condition

if b.isHidden // condition to check if the button is hidden -
{
b.isHidden = false // set the button to be visible
}

your if statement does not have a condition where its checking anything.