UILabel Setting Transparent Background Color?

Viewed 31716

I am looking to add a black label with a transparent background to my view (see below)

// ADD LABEL
UILabel *label = [[UILabel alloc] init];
[label setFrame:CGRectMake(124, 312, 72, 35)];
[label setText:@"Yay!"];
[label setTextAlignment:UITextAlignmentCenter];
[[self view] addSubview:label];
[label release];

When I add the label it always comes out black text on a white background. I have looked in the NIB and the only way I can see to make this work is set the background > color > opacity to 0, or in Xcode:

[label setBackgroundColor:[UIColor clearColor]];

Is this the right way to do this?

Cheers Gary

2 Answers

Swift 3 and 4:

yourView.backgroundColor = UIColor.clear
Related