Reputation: 2343
Quite simple question: I want to change the opacity of UIView and keep font above it with alpha = 1.0.
So as you can see there are two labeles and under them is UIView. I've set the opcaity of the UIView (for example: @IBOutlet weak var coView: UIView!
self.coView.alpha = 0.8
). The result is that both UIView and labels are more transparent and I want to keep label's text on alpha = 1.0. Is it possible to do without changing stack views and constraints?
Upvotes: 0
Views: 1823
Reputation: 1143
Instead of changing the Alpha of the Object you should leave the alpha at 1 and choose a custom Background colour (in the Attributes inspector):
Then in the custom colour widget change the opacity of the colour as desired.
Upvotes: 2
Reputation: 3787
Use
coView.backgroundColor = UIColor.black.withAlphaComponent(0.8)
It's super annoying and not precisely what you wanted, but it's a way around it. It sets the background color of the coView with an alpha value, which effectively gives you what you want.
Upvotes: 3
Reputation: 768
Changing the alpha of the UIView changes how all its subviews are seen to the new alpha set. There no way to actually avoid this, but you can go around this by using some other auxiliary views.
For example, inside your UIView pm
, you could have another subView called backgroundView
, which is on the back and that's the one you set the background color. Every other element inside your UIView pm
would be on top of the backgroundView
with a clear background color.
If you want to only change the alpha of the color, you just change the alpha to the backgroundView
and the other elements in UIView pm
will remain with the same alpha
Upvotes: 1