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 open a second view from first view in iOS using SwiftUI?

In SwiftUI, you can open another view (or navigate to another view) on the click of a button by utilizing navigation views and navigation links. Here’s a basic example of how to achieve this:

question swiftui April 2, 2024 How to declare an array of Views in SwiftUI?

In SwiftUI, you can declare an array of View using the standard Swift array syntax. Here’s how you can do it: