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.