I want to add a dark screen over all my views, and then present a notification window above it, like in Tweetbot 3:
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?
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() ).
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.
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.
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With