iosswiftuser-interfaceuiviewcontrollerappdelegate

iOS App not using full height of the screen


I created a sample iOS app, where I removed the storyboard, the launch screen, the SceneDelegate and created a blank UIViewController

MainViewController:

class MainViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .green
    }
}

AppDelegate:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.rootViewController = MainViewController()
        window?.makeKeyAndVisible()

        return true
    }
}

Info.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>

My problem is that my view is not taking the whole height of the screen, I thought that UIWindow(frame: UIScreen.main.bounds) should suffice but I keep getting this screen

enter image description here


Solution

  • "where I removed ... the launch screen"

    This is the issue. All iOS apps MUST have a launch screen storyboard, even if the rest of the app is done without storyboards. This is at least true for UIKit based apps, not sure about SwiftUI apps.

    Without a launch screen storyboard the app falls back to only supporting old 3.5" (or maybe 4") iOS device sizes. This results in the black bars (known as letter boxing) on larger devices. The inclusion of the launch screen storyboard tells the app that it can handle all possible screen sizes.

    Your launch screen storyboard should replicate a greatly simplified version of your app's initial screen. The whole idea is to give the user the illusion of your app launching faster than it really does. Though the utility of this has diminished on newer, faster hardware.