Search code examples
iosswiftxcodeswiftui

SwiftUI view being rendered in small window instead of full-screen when using Xcode 11


I recently created a new SwiftUI project using the beta for Xcode 12. Then I tried to open this project in the non-beta Xcode 11, and after updating the code to use a SwiftUI 1.0-style AppDelegate, I was able to build and run the app. The issue is that now that I have moved to Xcode 11, the app renders inside of a small frame instead of taking up the whole screen.

Here is a simplified example:

Xcode 12 vs. Xcode 11

SwiftUI app taking up whole screen SwiftUI rendering in small frame, not full screen


My simplified view's code is as follows:

struct ContentView: View {
    var body: some View {
        VStack {
            Text("Hello World!")
        }
    }
}

AppDelegate:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }
}

SceneDelegate:

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).

        // Create the SwiftUI view that provides the window contents.
        let contentView = ContentView()

        // Use a UIHostingController as window root view controller.
        if let windowScene = scene as? UIWindowScene {
            let window = UIWindow(windowScene: windowScene)
            window.rootViewController = UIHostingController(rootView: contentView)
            self.window = window
            window.makeKeyAndVisible()
        }
    }

I have tried creating a new Xcode 11 project (which renders properly) and comparing its contents to my own project's, but so far I have not been able to find any difference between its AppDelegate, SceneDelegate, ContentView, build settings, etc.

Is there an option that should be changed in order to have SwiftUI render full-screen in the Xcode 11 project?


Solution

  • This is caused because the Xcode 11 project is missing a Launch Screen.

    This can be resolved by doing the following:

    • Right click on your project's name, choose New File…, and select Storyboard.

    • In the storyboard, add a new View Controller.

    • In your app target's settings, find the "App Icons and Launch Images" section.

    • Select your launch screen from the dropdown:

      enter image description here

    Now run your application and the SwiftUI view will fill up the whole screen!