Search code examples
uibuttonios9states

Why is the background color of my UIButton not affected in state config?


I am trying to configure UIButton disabled state using attribute inspector 'state config.' How can I configure the background color for the disabled state?


Solution

  • Try this:

    @IBAction func buttonStateChanged(sender: UIButton) {
            if(sender.selected){
            sender.backgroundColor = UIColor(red: 1.0, green: 0.0, blue: 0.2, alpha: 1.0)
            }else{
                sender.backgroundColor = UIColor(red: 1.0, green: 0.0, blue: 0.2, alpha: 1.0)
            }
        }