Skip to content

Instantly share code, notes, and snippets.

@ldenoue
Last active December 17, 2019 14:27
Show Gist options
  • Save ldenoue/d97da840bb115ff3637a702aaacdefb9 to your computer and use it in GitHub Desktop.
Save ldenoue/d97da840bb115ff3637a702aaacdefb9 to your computer and use it in GitHub Desktop.
show and hide a fullscreen overlay UIView with a spinner; works even in Action/Share extensions that don't have [UIApplication sharedApplication]
#define OVERLAY_VIEW_TAG 298739
-(void)showSpinner
{
UIView *back = [[UIView alloc]initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height)];
back.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
back.tag = OVERLAY_VIEW_TAG;
[self.view addSubview:back];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.center = back.center;
spinner.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleTopMargin;
[back addSubview:spinner];
[spinner startAnimating];
self.navigationController.navigationBar.layer.zPosition = -1;
}
-(void)hideSpinner
{
[[self.view viewWithTag:OVERLAY_VIEW_TAG] removeFromSuperview];
self.navigationController.navigationBar.layer.zPosition = 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment