UIView在NavigationBar和StatusBar之上

时间:2016-10-25 14:49:58

标签: swift uiview uinavigationbar uistatusbar

我需要在NavigationBar和StatusBar上方以全屏模式显示UIView 我怎么能这样做?

P.S。对不起我的英文

View above NavigationBar and StatusBar

2 个答案:

答案 0 :(得分:4)

以下代码将为您提供帮助。您可以将颜色更改为所需的颜色,以达到所需的效果。

UIWindow *window = [[[UIApplication sharedApplication] delegate] window];

UIView *blue = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[blue setBackgroundColor:[UIColor blueColor]];
[window addSubview: blueView];

Swift Code:

if let applicationDelegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate? {
   if let window:UIWindow = applicationDelegate.window {
      let blueView:UIView = UIView(frame: UIScreen.main.bounds)
      blueView.backgroundColor = UIColor.blue.withAlphaComponent(0.75)
      window.addSubview(blueView)
   }
}

答案 1 :(得分:0)

你可能想看看这个人的答案。

How to make a UIView that can cover the navigation bar?

基本上,不是将第二个视图设置为主视图的子视图,而是将第二个视图设置为导航控制器的子视图。