adit
adit

Reputation: 33654

UILabel alpha causes text to fade as well

Is there a way such that I can set the alpha of a UILabel, but it doesn't fade out the text of the UILabel? Meaning just the background?

Upvotes: 2

Views: 1151

Answers (2)

Kevin
Kevin

Reputation: 56089

As the text is a part of the label, if you set the alpha for the label the text fades appropriately. What you want is to set a backgroundColor with the appropriate alpha:

myLabel.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.5];

Upvotes: 9

Jesse Black
Jesse Black

Reputation: 7976

You may have to create a background view (UIView will suffice), and put the UILabel on top (not as a subview, because the alpha value of the background view affects all of its subviews)

Upvotes: 2

Related Questions