In an iphone app/ios, how do i make a transparent 'loading' overlay that covers the navigation bar and keyboard?
I've tried the following but it doesn't cover either the nav bar nor the keyboard:
UIView *overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
overlay.backgroundColor = [UIColor colorWithWhite:0 alpha:.5];
[self.view addSubview:overlay];
Thanks
If you'd like a simple library that will take care of it, David Sinclair's DSActivityView is good.
sometimes when I'm lazy to use other libraries I just do this:
// create a custom black view
UIView *overlayView = [[UIView alloc] initWithFrame:self.navigationController.view.frame];
overlayView.backgroundColor = [UIColor blackColor];
overlayView.alpha = 0.8;
overlayView.tag = 88;
// create a label
UILabel *message = [[UILabel alloc] initWithFrame:self.navigationController.view.frame];
[message setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:25.0f]];
message.text = @"message to my dear user";
message.textColor = [UIColor whiteColor];
message.textAlignment = NSTextAlignmentCenter;
message.tag = 99;
// and just add them to navigationbar view
[self.navigationController.view addSubview:overlayView];
[self.navigationController.view addSubview:message];
and then call a method that finds those views, fades them out and deletes them:
-(void) removeOverlayViews{
UIView *view = (UIView *)[self.navigationController.view viewWithTag:88];
UILabel *label = (UILabel *)[self.navigationController.view viewWithTag:99];
[UIView animateWithDuration:0.5
animations:^{
view.alpha = 0.0;
label.alpha = 0.0;
}
completion:^(BOOL finished){
[view removeFromSuperview];
[label removeFromSuperview];
}
];
}
sometimes I just want to show a message for a few seconds so I call this right after I add overlay views to navigationController:
[self performSelector:@selector(removeOverlayViews) withObject:nil afterDelay:4];
Add it to self.view.window
instead. That may not cover the keyboard though. In which case you need to create your own window. Though this is not recommended by Apple. Which means: be careful and thorough in your implementation.
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