Adjust alpha of UIColor

Eric picture Eric · Jun 19, 2015 · Viewed 51.6k times · Source

I set a UIColor using rgb to a background of a UILabel. I'm trying to adjust the alpha only. How can I modify the alpha of an existing rgb UIColor?

Edit

Basically I have UILabels that have a set UIColor (using rgb), and I won't know what color the UILabels are. At a certain point, I will have to change the labels alpha`. How can I just change the labels color alpha?

Answer

Eric picture Eric · Jun 19, 2015

colorWithAlphaComponent: did the trick.

So what I had to do was:

self.mylabel.backgroundColor = [self.myLabel.backgroundColor colorWithAlphaComponent:0.3];