I have the following UIButton:
// create footerView
let footerView: UIView = UIView()
footerView.backgroundColor = UIColor.yellowColor()
self.view.addSubview(footerView)
footerView.snp_makeConstraints { (make) -> Void in
make.left.equalTo(self.view.snp_left)
make.right.equalTo(self.view.snp_right)
make.height.equalTo(self.footerHeight)
make.bottom.equalTo(self.view.snp_bottom)
}
let footerButton: UIButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
footerButton.setTitle("OK", forState: UIControlState.Normal)
footerButton.backgroundColor = UIColor.redColor()
footerButton.tintColor = UIColor.whiteColor()
footerButton.setTitleColor(UIColor.grayColor(), forState: UIControlState.Highlighted)
footerView.addSubview(footerButton)
footerButton.snp_makeConstraints { (make) -> Void in
make.center.equalTo(footerView)
make.left.equalTo(footerView.snp_left).offset(45)
make.right.equalTo(footerView.snp_right).offset(-45)
}
Edit: I could use
footerButton.setBackgroundImage(redImage, forState: UIControlState.Highlighted)
but this would destroy the auto layout and border radius if I tapp the button.
How can I change the backgroundColor of the button on UIControlState.Highlighted
?