Reputation: 249
I have an image and a label on it.
To improve readability I would like the transparent background for the label a little bit darker.
Here's an image to figure out what I'm looking for:
Any idea how to perform that? I've already tried with Blur transparency but it's not working.
Upvotes: 2
Views: 2579
Reputation: 2865
You can set the background color and transparency for the label in the following way:
label.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.7)
To make your background darker set the alpha (transparency) to a higher value. Completely opaque is an alpha of 1.0 and completely transparent is an alpha of 0.0. So experiment around a bit with the alpha until you find a value you like.
Of course you can also adjust the red, green and blue values to a value of your liking. An RGB of 0,0,0 will make the darkest option, black, which may be the most useful for you here.
Edit: You can also use the following alternatives to achieve the same effect:
label.backgroundColor = UIColor(white: 0.0, alpha: 0.7)
or
label.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.7)
Edit: In Swift 3 this would be:
label.backgroundColor = UIColor.black.withAlphaComponent(0.7)
Upvotes: 3
Reputation: 92
label.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7]
Upvotes: -1