From what you've described it should be easy. see the code below.
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 300, height: 40))
button.setTitle("Click me", for: .normal)
button.backgroundColor = UIColor.red
button.tintColor = UIColor.white
button.addTarget(self, action: Selector("handleTap"), for: .touchUpOutside)
view.addSubview(button)
func handleTap(sender: UIButton) {
if sender.backgroundColor == UIColor.red {
sender.backgroundColor = UIColor.blue
} else {
sender.backgroundColor = UIColor.red
}
}
The above code depends on how you are implementing your UI and where the code is. if you can prvoide more information on your implementation I can update this and make it more specific to your case.