I'm currently developing a simple iOS app using Xcode and Swift. In my app, there is a button that some times is disabled/enabled, depending on something else the user have touched. But when I set "button.enabled = false", I also what the button to grey out, so that the user knows the button is currently disabled. How could this be done?
Use following code for customizing button's title for disabled state. You can call it inside viewDidLoad
:
button.setTitleColor(UIColor.grayColor(), forState: .Disabled)
If you would like to customize a background colour for the disabled button, use approach from this answer: How to change background color of UIButton when it's highlighted
Swift 5.3:
button.setTitleColor(.systemGray, for: .disabled)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments