Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you change UIButton image alpha on disabled state?

I have a UIButton with an image and on its disabled state, this image should have .3 alpha.

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; UIImage *arrowImage = [UIImage imageNamed:@"arrow.png"]; [button setImage:arrowImage forState:UIControlStateNormal];  // The arrow should be half transparent here [button setImage:arrowImage forState:UIControlStateDisabled]; 

How do I accomplish this?

UPDATE: I noticed, by default UIButton does reduce the alpha of the image on disabled state (probably at .5?). But I'd like to know how to fine-tune this value.

like image 770
pixelfreak Avatar asked Sep 25 '11 00:09

pixelfreak


1 Answers

If setting alpha while the button is disabled doesn't work, then just make your disabled image at the alpha value you desire.

Just tested this, you can set the alpha on the UIButton, regardless of state and it works just fine.

self.yourButton.alpha = 0.25; 
like image 122
EricLeaf Avatar answered Sep 18 '22 21:09

EricLeaf