MusiGenesis MusiGenesis - 1 month ago 4
iOS Question

How can I have an opaque UIView as a subview of a semi-transparent UIView?

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 UIView as a subview - the problem is that when I do this, my newly-added subview is also partially transparent.

Is there any way to make a subview "ignore" the alpha value of its superview and be itself fully opaque?

Answer

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]
Comments