Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manually Created UIWindow is Wrong Size

I am learning how to create an iOS app without Interface Builder (i.e. storyboards, xibs, etc.). Below is the basic app delegate class I am working with. The problem is that when displayed the UIWindow does not use up the full screen of the device (see attached screenshot). This occurs on all the devices and simulators I test with. Why isn't the fullscreen being used?

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
  lazy var window: UIWindow? = {
    debugPrint("AppDelegate: Creating Window")

    let screen: UIScreen = UIScreen.mainScreen()
    let window: UIWindow = UIWindow.init(frame: screen.bounds)

    window.backgroundColor = UIColor.whiteColor()

    return window
  }()

  lazy var rootViewController: ShapesViewController = {
    debugPrint("AppDelegate: Creating Root View Controller")

    let rootViewController = ShapesViewController.init(nibName: nil, bundle: nil)

    return rootViewController
  }()

  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
    debugPrint("AppDelegate: applicationWillEnterForeground")

    window?.rootViewController = rootViewController
    window?.makeKeyAndVisible()

    return true
  }
}

Why doesn't the window use the whole screen?

like image 862
joshwbrick Avatar asked Aug 07 '16 19:08

joshwbrick


Video Answer


1 Answers

The problem turned out to be that I did not have a launch image or storyboard. For some reason without this the app defaults to the 3.5" size. Credit to this comment: A launch storyboard or xib must be provided unless the app requires full screen

like image 105
joshwbrick Avatar answered Sep 20 '22 05:09

joshwbrick