I have two image sets for "flag" button in my Images.xcassets: flag-highlighted and flag-normal, where each set has 3 images of size x1, x2, x3
I use the flag-normal image set for the Image attribute in the attributes inspector for this button. But, where/how do I specify the flag-highlighted image set for the selected state?
You must set the content mode for the image inside the UIButton. The solution is to update the contentMode of the Image when you are using a foreground image inside a button along with the contentMode of the UIButton .
You can use the following code. class ViewController: UIViewController { var gameTimer: Timer! @IBAction func btnClick(_ sender: Any) { let button = UIButton() if (button. isSelected) { print(" Not Selected"); } else { print(" Selected"); } } override func viewDidLoad() { super.
A control that executes your custom code in response to user interactions.
You can set image for specific button state via interface builder by using state config option.
Choose selected option and then pick your image for selected state.
If anyone is wondering why the state config is missing for button in xcode 13, you need to change button's style from plain to default after that state config drop down will appear and you can change it to whatever you want
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With