SergGr
SergGr

Reputation: 23788

Different alpha for subviews in the same container

I have a question similar to the Can you override a parent UIView's alpha value on one of its subviews?

In some cases I want to show custom semi-transparent full-screen overlay view over current view. The trick is that I want it to have custom navigation bar at the top and some other contents (let it be label) and I'd like the navigation bar to be opaque i.e. paint over everything on the original view. At the same time I'd like all other contents to be semi-transparent. I don't want to interfere with main view's navigation bar because there might be no navigation bar at all. I'd like to create a single container view with navigation bar and all other contents on it and add it to the window. But none of combinations of background color and alpha for container, navigation bar and contents I can come up with seems to work.

The question I found suggests that it is impossible if container view is not opaque. My case might be slightly different because there is a simple border-line between transparent and opaque parts. So I still hope that there is some easy way. Or do I have to manage opaque navigation bar and transparent contents views separately anyway?

Upvotes: 2

Views: 2888

Answers (2)

TechZen
TechZen

Reputation: 64428

Edit: Disregard this answer. I misunderstood the question.

The previous post's answer is incorrect (as I understood the question.) The alpha for each individual view is set independently. You need to adjust the alpha to the level you want as you add each view, in Interface Builder or after you load from nib.

If you don't want to cover the navigation bar, you can (1) make position the overlay view's frame below the navigation bar or (2) create two sibling views in the overlay view, one view is transparent over the navigation bar and the other has your translucent elements.

Upvotes: 0

Ole Begemann
Ole Begemann

Reputation: 135588

If I understand your question correctly, you should make your container view completely transparent (backgroundColor = [UIColor clearColor]) and add the opaque navigation bar and a semi-opaque content view to the container view.

Upvotes: 1

Related Questions