简体   繁体   中英

How to add a subview to cover UINavigation barin UIViewController?

Hello I want to add a UIView on 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

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM