tags:

views:

200

answers:

2

I'd like to show an overlay view similar to what you see when you perform a 'Search in Contacts app where the SearchBar is visible under the toolbar while the gray overlay covers up all of the content below.

For my view, I'd like to have an UITextField and button shown visible while the rest of screen is gray with the rest of the existing contents as grayed-over and no SearchBar.

Things I tried:

  1. I can have one view that encases both UITextField and button with the view's alpha level set to 0.5. But this yields grayed appearance for everything, including the UITextField and button, which is not what I'm trying to achieve.

  2. I then tried two child views within a parent UIView, with one subview containing the controls while the other one is blank. Set the parent UIView to have 0.5 alpha -> this is not right either.

  3. Continuing with two child views within a parent UIView, set the parent view to have alpha of 1.0 and then the the blank-view to have an alpha level of 0.5, it's still not right.

So what's a good way to achieve this?

A: 

I would've thought #3 would be the correct way to do it. Are you sure you have the parent and the overlay views's opaque property set to NO?

Daniel Dickison
Parent UIView alpha set to 1.0, opaque: not checked. Blank-subview alpha set to 0.5, opaque: checked. When you say 'overlay', are you referring to the blank-subview or something else?
Alexi Groove
Yes, I meant the "blank" overlay (presumably it's not really blank, but a solid black). Also, follow Ramin's advice and make sure the parent view's backgroundColor is [UIColor clearColor].
Daniel Dickison
+1  A: 

Option 3 is the way to do it but make sure you're adding them in the right order i.e. transparent view added as first subView to parent view then the text field. This way the text field is on top.

Also, don't forget to set the backgroundColor attribute of the parent view to [UIColor clearColor].

Ramin
thanks this worked in conjunction with a Controller and added the main transparent view as the topmost.
Alexi Groove