I wanted to add a view to UIWindow with the following code:
AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate; UIWindow *window = delegate.window; UIView *aView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)]; aView.backgroundColor = [UIColor blackColor]; [window addSubview:aView];
This code does not work. I wanted to clone a UIAlertView property. It will pop up above everything when we call [alertViewInstance show]; .
Tried this as well:
UIView *aView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)]; UIWindow* window = [UIApplication sharedApplication].keyWindow; if (!window) { window = [[UIApplication sharedApplication].windows objectAtIndex:0]; } [window addSubview:aView]; [window bringSubviewToFront:aView];
source share