开发者社区> 问答> 正文

求解 自定义一个在StatusBar位置上的UIWindow不能显示

我在一个ViewController 中定义一个在Statusbar上显示自定义的UIwindow 怎么都不能显示出来,不知道为什么?代码如下:

XCode 6.1

 UIWindow * statusWindow = [[UIWindow alloc] initWithFrame:[UIApplication sharedApplication].statusBarFrame]; 

       [statusWindow setWindowLevel:UIWindowLevelAlert + 1]; 

    [statusWindow setBackgroundColor:[UIColor clearColor]]; 

     

    UILabel * statusLabel = [[UILabel alloc] initWithFrame:statusWindow.bounds]; 

    statusLabel.text = @"Loading..."; 

    statusLabel.textColor = [UIColor blueColor]; 

    statusLabel.textAlignment = NSTextAlignmentCenter; 

    statusLabel.backgroundColor = [UIColor blackColor]; 

    [statusWindow setHidden:NO]; 

    [statusWindow setAlpha:1.0f]; 

    [statusWindow addSubview:statusLabel]; 

     

    [statusWindow makeKeyAndVisible]; 

展开
收起
杨冬芳 2016-06-27 15:37:54 1624 0
1 条回答
写回答
取消 提交回答
  • IT从业

    因为statusWindow是个局部的对象,执行完[statusWindow makeKeyAndVisible];后被自动释放;可以试试将其设为属性,就会显示了。

    2019-07-17 19:47:45
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载