Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make my activity indicator view cover all screen?

So when a user clicks on a button in my app, I would like to create a new view with an activity indicator and cover the whole screen with it until the button action finishes.

However, my activity indicator view is covering only inside of a table view, it looks like this:

enter image description here

How to make it cover whole screen? Including the navigation controller and table view toolbar.

Here is my code I use to create the view:

self.overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.overlayView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
self.activityIndicator.center = self.overlayView.center;
[self.overlayView addSubview:self.activityIndicator];
[self.activityIndicator startAnimating];
[self.tableView addSubview:self.overlayView];
like image 298
Richard Knop Avatar asked Apr 14 '12 20:04

Richard Knop


2 Answers

Change

[self.tableView addSubview:self.overlayView];

To

[self.navigationController.view addSubview:self.overlayView];

Set the overlay's rect accordingly.

like image 76
CodaFi Avatar answered Nov 02 '22 19:11

CodaFi


Do this:

[[UIApplication sharedApplication].keyWindow addSubview:self.overlayView];
like image 44
shabbirv Avatar answered Nov 02 '22 21:11

shabbirv