UIAlertController
When we use UIAlertController then we require view controller to present, if it is not there it will not work or if launched without getting present view then it is not possible to remove from view controller so on that time UIWindow is used to create the custom alert controller . it will run on the top root of the window .
To Launch :—
Ex : UIWindow *currentWindow = [UIApplication sharedApplication].keyWindow;
[className alertController:currentWindow];
To Remove :—
if([currentWindow viewWithTag:121212])
[[currentWindow viewWithTag:121212] removeFromSuperview];
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
+(void)alertController:(UIWindow *)alertnew { UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; blurEffectView.tag = 121212; UIWindow *currentWindow = alertnew; UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; spinner.color = [UIColor blackColor]; [spinner startAnimating]; UIView *alertView = [[UIView alloc] initWithFrame:CGRectMake(0,0, 256, 96)]; alertView.backgroundColor = [UIColor whiteColor]; alertView.layer.cornerRadius = 10; UILabel *sortTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 256, 20)]; [sortTitle setTextColor : [GlobalData colorWithHexString : @"000000"]]; [sortTitle setBackgroundColor : [UIColor clearColor]]; [sortTitle setFont : [UIFont fontWithName : @"Trebuchet MS" size : 18.0f]]; [sortTitle setText : @"Please Wait..."]; sortTitle.adjustsFontSizeToFitWidth = YES; sortTitle.textAlignment = NSTextAlignmentCenter; [alertView addSubview : sortTitle]; UIView *sampleView = [[UIView alloc] initWithFrame:CGRectMake(0,45, 256, 40)]; sampleView.backgroundColor = [UIColor whiteColor]; [sampleView addSubview:spinner]; [alertView addSubview:sampleView]; spinner.center = CGPointMake(sampleView.frame.size.width / 2, sampleView.frame.size.height / 2); alertView.center = currentWindow.center; blurEffectView.frame = currentWindow.bounds; [blurEffectView addSubview:alertView]; [currentWindow addSubview:blurEffectView]; } |