How to add view in UIWindow?

前端 未结 8 1396
星月不相逢
星月不相逢 2021-02-14 22:42

I wanted to add a view in UIWindow with following code:

 AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
 UIWindo         


        
相关标签:
8条回答
  • 2021-02-14 23:22

    Try with this code:

    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        UIWindow* window = [UIApplication sharedApplication].keyWindow;
        if (!window) {
            window = [[UIApplication sharedApplication].windows objectAtIndex:0];
        }
    
        UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
        aView.backgroundColor = [UIColor redColor];
        aView.center = window.center;
        [window insertSubview:aView aboveSubview:self.view];
        [window bringSubviewToFront:aView];
    }
    
    0 讨论(0)
  • 2021-02-14 23:25

    i think you are missing this. check once.

    [self.window makeKeyAndVisible];
    
    0 讨论(0)
提交回复
热议问题