Bad frame UIScreen.main.bounds

Subject: Help Needed: UIScreen.main.bounds Frame Issue in AnyFormatKitFramework

Hello everyone,

I hope you’re doing well! I’m reaching out to seek assistance with an issue I’m encountering while working on my project using Tuist.

I have the following Project.swift file:

import ProjectDescription

let project = Project(
    name: "AnyFormatKitFramework",
    targets: [
        .target(
            name: "AnyFormatKitFramework",
            destinations: .iOS,
            product: .app,
            bundleId: "RI.AnyFormatKitFramework",
            infoPlist: .default,
            sources: ["Sources/**"],
            resources: ["Resources/**"],
            dependencies: [
                .external(name: "AnyFormatKit")
            ]
        ),
        .target(
            name: "AnyFormatKitFrameworkTests",
            destinations: .iOS,
            product: .unitTests,
            bundleId: "RI.AnyFormatKitFrameworkTests",
            infoPlist: .default,
            sources: ["Tests/**"],
            resources: [],
            dependencies: [.target(name: "AnyFormatKitFramework")]
        )
    ]
)

In my main.swift and AppDelegate.swift, located in Sources/AnyFormatKitFramework, I have the following code:

UIApplicationMain(
    CommandLine.argc,
    CommandLine.unsafeArgv,
    nil,
    NSStringFromClass(AppDelegate.self)
)

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

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

MainViewController is a standard view controller where I set view.backgroundColor = .white inside viewDidLoad.

However, when I run the project on any simulator, I encounter an issue where the frame of UIScreen.main.bounds appears to be truncated. I’ve attached screenshots below to illustrate the problem.

Has anyone experienced a similar issue or have any suggestions on how to resolve this? Any help would be greatly appreciated!

Thank you in advance for your assistance!

Hi @Alexandr-Ivantsov

That’s most likely because the launch screen in your project. The launch screen is configured in the Info.plist of the application target.

You can either set a color or image or a storyboard containing the launch screen.

1 Like