Loading...

How to hide the title bar in a SwiftUI macOS app?

question swiftui macOS
Ram Patra Published on January 26, 2024

Let’s say you have a view named ContentView and your main App file looks like this:

@main
struct ExampleApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

To hide the title bar in the main window, you can simply add this line .windowStyle(.hiddenTitleBar) to the WindowGroup like this:

@main
struct ForegroundApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        .windowStyle(.hiddenTitleBar)
    }
}

Note: Sometimes the Xcode preview doesn’t hide the title bar even after applying the above code. However, building and running the project will hide the title bar as expected.

Ram Patra Published on January 26, 2024
Image placeholder

Keep reading

If this article was helpful, others might be too

question swiftui iOS April 2, 2024 How to force an app or a view to open in landscape only mode in iOS using SwiftUI?

In SwiftUI, you can force an app to open in landscape mode by configuring the supported interface orientations in your app’s target settings. Here’s a step-by-step guide to configuring interface orientations in Xcode:

question swiftui swift May 29, 2022 How to open a new window in SwiftUI?

Although many things in SwiftUI are idiomatic and straightforward, showing your view in a new window needs a bit of coding to do. Hence, this short post.

question swiftui swift September 30, 2023 How to open the Settings view in a SwiftUI app on macOS 14.0 (Sonoma)?

In macOS 14.0 (Sonoma), Apple removed support for NSApp.sendAction to open the Settings view in your SwiftUI app. You now have to use SettingsLink like below: