Frakcool
Frakcool

Reputation: 11163

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

Upvotes: 4

Views: 1715

Answers (4)

Niels Hoogendoorn
Niels Hoogendoorn

Reputation: 738

I had this issue using the SwiftUI lifecycle (and accidentally starting a MacOs project instead of an iOS one and added the iOS target later).

I fixed this by:

  1. Go to the target's build settings
  2. Search for Launch Screen (Generation)
  3. Turn the value to Yes

Upvotes: 1

Deivi
Deivi

Reputation: 245

For anyone coming from SwiftUI, adding an empty image name to Info.plist should work as well.

<key>UILaunchScreen</key>
<dict>
    <key>UIImageName</key>
    <string></string>
</dict>

Info.plist configuration

Upvotes: 9

7RedBits.com
7RedBits.com

Reputation: 483

I had to also add the newly created launch screen to: General > Launch Screen File

I was building a Mac app and added iOS later, this caused the issue.

Upvotes: 0

HangarRash
HangarRash

Reputation: 15039

"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.

Upvotes: 6

Related Questions