Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add UIImageView that covers navigation bar

I think I'm missing something simple here. I need to create a semi-transparent UIImageView that covers the entire screen including the navigation toolbar. How do I do this?

This is what I'm trying to do ...

enter image description here

like image 679
Eric Avatar asked Jan 15 '12 00:01

Eric


2 Answers

This is a possible solution:

UIImage *image=[UIImage imageNamed:@"whatever.png"];
UIImageView *overlay=[[UIImageView alloc] initWithImage:image];
overlay.alpha=0.5;
[[[[UIApplication sharedApplication] delegate] window] addSubview:overlay];

EDIT:

  • It is likely that you would not be setting the alpha value for the overlay, but rather use a transparent PNG with embedded transparence levels. Still, it's a possibility.
  • When not using ARC, you should [overlay release].
like image 143
magma Avatar answered Nov 02 '22 03:11

magma


To focus the above answer a little bit, you just need to be clear on how views clip to what parts of the device's screen that they "own".

The key point is that in a navigation view, the Navigation bar itself is not part of your [myController view] - your view controller's view is everything below the bar and anything you do in that view clips to the rectangle below that bar.

The bar is, however, part of your [myAppDelegate window]. The window is essentially the entire screen of your device, while the views are sub portions responsible for managing their specific bounds. So calling [[myAppDelegate window] addSubView:] will display above the bar where [[myViewController view] addSubView:] will not.

like image 30
Todd Masco Avatar answered Nov 02 '22 01:11

Todd Masco