1

Hello I want to add a UIViewon top of my current view controller. So I did like this.

- (void)viewDidLayoutSubviews
{

    UIView *vwOverlay=[[UIView alloc] initWithFrame:self.view.frame];
   [vwOverlay setBackgroundColor:[UIColor blackColor]];
   [vwOverlay setAlpha:0.5];
   [self.view addSubview:vwOverlay];
}

but this is adding top of my view but behind my navigation bar.Istill can clearly see navigation bar title and navigation menu items and also can click navigation bar items. But I want to cover this navigation bar too from my new view. How can I do this? Please help me. Thanks

user1960169
  • 3,533
  • 12
  • 39
  • 61
  • I found the answer [here](http://stackoverflow.com/a/21850538/1960169). Adding it to the window solved my problem. – user1960169 May 04 '16 at 05:34
  • 1
    Possible duplicate of [Add a UIView above all, even the navigation bar](http://stackoverflow.com/questions/21850436/add-a-uiview-above-all-even-the-navigation-bar) – Vinoth Krishnan May 04 '16 at 06:00

1 Answers1

0

Use this code

UIWindow *window = [[UIApplication sharedApplication] keyWindow];
CGSize screenBounds = [UIScreen mainScreen].bounds;
UIView *vwOverlay=[[UIView alloc] initWithFrame: screenBounds];
[vwOverlay setBackgroundColor:[UIColor blackColor]];
[vwOverlay setAlpha:0.5];
[window addSubview:vwOverlay];
Imran
  • 3,045
  • 2
  • 22
  • 33