Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton won't gray out

Isn't UIButton supposed to become grayish/grayer when enabled=NO ?

I have a simple UIButton on a blackbackground (no custom images, no custom nothing, just dragged it with IB and changed size and title).

And when I set it programatically to become disabled it stays white as hell!

For now I'm using a small stupid workaround: hidden blackbg 0,5 alpha UIView on top of the button that becomes hidden=NO when I need to disable the button... but I would like to set the button properly...

Any thoughts?

like image 675
xfze Avatar asked Jun 10 '11 16:06

xfze


People also ask

Why you shouldn t gray out disabled buttons?

Gray is often used to communicate a low priority button (e.g., cancel buttons). When they see a gray button, they won't know for sure if it's disabled unless they click it. This uncertainty and unpredictability is not an optimal user experience. When making your button transparent, adjust the opacity, not the color.

How do I turn off highlighting in Uibutton?

make your button Type - "Custom" and Uncheck - Highlighted Adjust image and you are done.


2 Answers

There is another way without having to alpha the whole button:

[startButton setTitleColor:[UIColor grayColor] forState:UIControlStateDisabled]; 

Then whenever you set the enabled property to NO, the button's text will automatically gray out.

like image 60
jowie Avatar answered Sep 26 '22 08:09

jowie


There is no way to make a UIButton "grayer". But you can use that trick :

UIButton *myButton; myButton.alpha = 0.4; myButton.enabled = NO; 

So your UIButton looks like unusable ;)

like image 23
Pierre Espenan Avatar answered Sep 24 '22 08:09

Pierre Espenan