Search code examples
iosxcodebuttonswiftibaction

Swift: 'Tap to Begin' button - delete itself


I have a tap to begin button in my main view controller. It is linked to an IBAction that will detect when it is touched. However, I am wondering what would be the best way of hiding the button: deleted, moved off screen, or hidden completely - and what code should I put in my IBAction to do this?

Thanks


Solution

  • The easiest way is to just hide it. Create an outlet connection so you can reference the button as an class instance property, then set its hidden property to true from the tap handler:

    @IBOutlet private weak var btnBegin: UIButton!
    
    @IBAction func didTapBegin() {
        ...
        btnBegin.hidden = true
    }