Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the UIButton background transparent?

I tried use a transparent png as a background, but not success. How can I solve it ? thz.

like image 395
Tattat Avatar asked May 10 '10 16:05

Tattat


3 Answers

Changing the Type to Custom in the Inspector window (Interface builder) worked for me.

like image 72
DineshNS Avatar answered Oct 08 '22 19:10

DineshNS


To create a transparent button (without using an image):

- (void)viewDidLoad
{
    [super viewDidLoad];

    CALayer *layer = <your button>.layer;
    layer.backgroundColor = [[UIColor clearColor] CGColor];
    layer.borderColor = [[UIColor darkGrayColor] CGColor];
    layer.cornerRadius = 8.0f;
    layer.borderWidth = 1.0f;
}
like image 22
David H Avatar answered Oct 08 '22 18:10

David H


This is a good one too:

[button.layer setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.5].CGColor];
like image 7
ogaihtorecic Avatar answered Oct 08 '22 18:10

ogaihtorecic