Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a dark screen that covers all other views (including navigation bar and status bar)?

I want to add a dark screen over all my views, and then present a notification window above it, like in Tweetbot 3:

enter image description here

However, I'm not totally sure how this is accomplished.

Adding a dark view with the size of the screen as its frame does not work, as below: (navigation bar and status bar aren't covered)

UIView *darkOverlay = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
darkOverlay.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
[self.view insertSubview:darkOverlay behindSubview:self.view];

This covers everything except the status bar (so it comes pretty close, but as I have light status bar content it's still very jarring):

[[[UIApplication sharedApplication] keyWindow] addSubview:darkOverlay];

So how is something like this accomplished?

like image 242
Doug Smith Avatar asked Nov 04 '13 21:11

Doug Smith


People also ask

How do you make a navigation bar transparent in Swift?

You need to do three things to make a navigation bar transparent. Set background image to non-nil empty image ( UIImage() ). Set shadow image to non-nil empty image ( UIImage() ).

How do I change the navigation bar on my Iphone?

Change the Bar Style A user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page. This button opens an action sheet where users can change the background's appearance to default, black-opaque, or black- translucent.


2 Answers

You can try this method

    UIWindow* window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    window.windowLevel = UIWindowLevelAlert;
    window.opaque = NO;

    [window addSubview:someView];

    // window has to be un-hidden on the main thread
    [window makeKeyAndVisible];

Where "view" - is your custom popup.

like image 114
Che Avatar answered Sep 21 '22 22:09

Che


You have to do this:

CGRect screenRect = [[UIScreen mainScreen] bounds];
_darkCoverView = [[UIView alloc] initWithFrame:screenRect];
_darkCoverView.backgroundColor = [UIColor blackColor];
_darkCoverView.alpha = 0.5;

[[[[UIApplication sharedApplication] delegate] window] addSubview:_darkCoverView];

It works for me, and the status bar is covered as well :)

like image 22
user1506145 Avatar answered Sep 17 '22 22:09

user1506145