views:

169

answers:

1

I wonder what is the way to gray out portion of a view similar to the way UIAlertView grays out everything except the message box? Right now i use another custom view on top of the target area, but it doesnt look as nice.

Any ideas?

+3  A: 

I get good results using the method you have already tried. perhaps fiddling around with the alpha is a good idea?

mask = [[UIView alloc] initWithFrame:window.frame];
[mask setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.78]];
[self.view addSubview:mask];

Then later in your code you can remove it:

[mask removeFromSuperview];
or
[mask setHidden:YES];

If you want to make it even better, I suppose you could try using a gradient, either programmatically, or as an image, and using this to darken the edges of the screen such that the content you are displaying forefront appears to be the light source.

coneybeare
That's exactly how I did, with alpha
Denis M