Snorlax Snorlax - 5 months ago 18x
Swift Question

Swift, Xcode: Changing UIButton Background and Text on Click

I want to change the background and text of the button on click, I tried several SO solutions but they haven't worked, you can see what I tried in my project:

I tried debugging it by putting a simple print statement and it looks like it doesn't ever go to it.



1) Create an IBAction from your UIButton and also an IBOutlet called button.

EDIT: As per your request (How to trigger the even when the button is TOUCHED, not RELEASED?):

enter image description here

2) Do this:

@IBAction func changes (sender: UIButton) {

    button.backgroundColor = UIColor.blueColor()

    button.setTitle("Button Title", forState: UIControlState.Normal)