Warm tip: This article is reproduced from stackoverflow.com, please click
cocoa-touch ios iphone uibutton

Disabled UIButton not faded or grey

发布于 2020-04-16 12:09:14

In my iPhone app, I have a UIButton which I have created in Interface Builder. I can successfully enable and disable it like this in my code ...

sendButton.enabled = YES;

or

sendButton.enabled = NO;

However, the visual look of the button is always the same! It is not faded or grey. If I attempt to click it though, it is enabled or disabled as expected. Am I missing something? Shouldn't it look faded or grey?

Questioner
Andy A
Viewed
13
1,531 2015-06-23 15:35

You can use following code:

sendButton.enabled = YES;
sendButton.alpha = 1.0;

or

sendButton.enabled = NO;
sendButton.alpha = 0.5;