Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set alpha of background of UIButton but not the title

Tags:

When I set the alpha of the button it also affects the opacity of the title. Is there a way to target only the background and leave the title alpha at 1.0?

like image 939
Jon Avatar asked Jul 05 '13 15:07

Jon


2 Answers

This works for me:

self.myButton.backgroundColor = [UIColor clearColor]; 

or if you don't want to have it completely clear, but still with transparency you can use:

self.myButton.backgroundColor = [UIColor colorWithRed:200.0/255.0 green:200.0/255.0 blue:200.0/255.0 alpha:0.5]; 

The second example would give you gray color with alpha 0.5.

SWIFT 4 Update

myButton.backgroundColor = .clear 

OR

myButton.backgroundColor = UIColor(red: 200.0/255.0, green: 200.0/255.0, blue: 200.0/255.0, alpha:0.5) 
like image 103
SasaT Avatar answered Oct 28 '22 07:10

SasaT


You can also change the alpha of the color in the storyboard,

see attached image:

change alpha of color in storyboard/interface builder

like image 20
brush51 Avatar answered Oct 28 '22 06:10

brush51