如何以编程方式创建UIView,使其不与状态栏重叠

时间:2016-10-09 22:09:28

标签: ios uiview uiviewcontroller

我在我的app委托中使用以下代码以编程方式创建应用程序的窗口和根控制器:

element.on("mouseup", (evet: JQueryEventObject) => {
  console.log('INFO: caret changed, new value: ', EditorEvents.GetCaretPosition(<HTMLInputElement>element[0]));

代码工作正常,但与根视图控制器关联的视图与状态栏重叠,我想避免(见下图)。

enter image description here

我该怎么办?特别是我希望状态栏具有浅灰色背景(类似于使用故事板创建的应用程序),并且还能正确处理方向更改。

由于

1 个答案:

答案 0 :(得分:2)

嗯,你可以做以下事情:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = [[UIViewController alloc] init];
    self.window.rootViewController.view.backgroundColor = [UIColor whiteColor];
    UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(0,
                                                               [UIApplication sharedApplication].statusBarFrame.size.height,
                                                               [UIScreen mainScreen].bounds.size.width,
                                                               [UIScreen mainScreen].bounds.size.height)];
    redView.backgroundColor = [UIColor redColor];
    [self.window.rootViewController.view addSubview:redView];

    [self.window makeKeyAndVisible];

    return TRUE;
}

应如下所示:

enter image description here