I have a UIView with an alpha of 0.5 which I add as a subview to my primary view in order to gray-out everything else. I want to add an additional UIView to this gray UIVie
Set the UIView background color alpha not it's alpha directly.
Objective-C
UIView *view;
...
view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.6];
It's not the same as:
view.backgroundColor = [UIColor blackColor];
view.alpha = .6;
Swift
view.backgroundColor = UIColor.black.withAlphaComponent(0.6)
No, not really. What you want is to take your overlay view, and make it just have a clear background color. As a subview of that new overlay place your view that will grey things out. And as a sibling view to that put your view you want to be opaque.
[OpaqueView] [DimmingView]
| |
[OverlayView]
No, any view will inherit the opacity of its parent.
Don't put it inside the semi-transparent view. Make it a sibling to semi-transparent view and put it over it using z-ordering.
This will only work if you have any image on the background.
Instead of reducing the alpha
of UIView
, add an UIImageView
on that view and then reduce the alpha of the UIImageView
.
now add your subviews on the UIView
.
your subviews will not take the alpha property anymore.. :)