Search code examples
swiftxcodeiboutletibaction

How to hide an action button in Swift?


I try to make a button invisible after pressing it. The Connection is an action and not an outlet, because pressing the button will call additional code.

@IBAction func startGame(_ sender: Any) {
    print("The game starts...")

}

This does not work, because the button is an action and not an outlet:

startGame.isHidden = true 

Is there another way to make an action button invisible and therefore not clickable?


Solution

  • Just create an IBOutlet of the same button and set its isHidden property to true once it's tapped.

    @IBAction func startGame(_ sender: Any) {
         startGameButton.isHidden = true
    }