9

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?

macinjosh
  • 5,581
  • 9
  • 45
  • 69

3 Answers3

14

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

Community
  • 1
  • 1
macinjosh
  • 5,581
  • 9
  • 45
  • 69
  • 2
    To quote the book ["iOS 9 Programming Fundamentals with Swift"](http://shop.oreilly.com/product/0636920044345.do) by Matt Neuberg (amazing tech writer!): The presence of a `Launch screen interface file base name` key in your *Info.plist* tells the system that your app runs natively on newer device types, such as the iPhone 6 and iPhone 6 Plus. Without it, your app will be displayed zoomed … you won't be getting all the pixels you're entitled to … – Basil Bourque Dec 23 '16 at 21:00
2

This always works for me (I don't see any clear difference though). Do you mind sharing your ShapesViewController code as well?

Updated to swift 4.2

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    window = UIWindow(frame: UIScreen.main.bounds)
    window?.rootViewController = ViewController()
    window?.makeKeyAndVisible()
    return true
}
Khaled Annajar
  • 12,558
  • 4
  • 30
  • 43
dvdblk
  • 1,110
  • 13
  • 21
  • The ShapesViewController is empty. I even changed the root view controller to a plain old UIViewController object and I got the same thing. I tried your sample code just to rule out any weirdness and it looks the same. – macinjosh Aug 07 '16 at 19:44
  • 1
    @macinjosh Maybe you should try out the sample code in a new plain project. Also did you delete the main.storyboard file? – dvdblk Aug 07 '16 at 19:52
0

I know sounds silly but... For a fresh project what macinjosh is saying works. For a project of mine in Xcode 8 and swift 3, it didn't (probably because I deleted the launch screen and had to create again). Just created new project fresh, and follow what macinjosh said. Then migrate all your files back in.

wolffan
  • 996
  • 8
  • 14