Not sure where you're setting the button color, but the code to change the color of the button will look something like this:
yourButton.backgroundColor = UIColor.blueColor() // this would make the button color blue.
You could set the button color programmatically in viewDidLoad
and change it when your IBAction
is called. For example, you could add this line in your IBAction
:
yourButton.backgroundColor = UIColor.redColor()
You may find this post helpful:
Change button background color using swift language
Update
Without seeing the code, I'm not sure what you're trying to do. You can change the fill of the rect with this code:
UIColor.whiteColor().setFill()
.
You could redraw the rect when your button is clicked and tie the color to a Bool
. Something like this would go inside the IBAction
tied to your button to toggle the state:
if self.myCondition == true {
self.myCondition = false
} else {
self.myCondition = true
}
Inside the code you're using to create your rect, you could do something like this:
if self.myCondition == true {
UIColor.greenColor().setFill()
} else {
UIColor.redColor().setFill()
}