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.

Presentify

Take your presentation to the next level.

FaceScreen

Put your face and name on your screen.

ToDoBar

Your to-dos on your menu bar.

Ram Patra Published on January 26, 2024
Image placeholder

Keep reading

If this article was helpful, others might be too

question swiftui swift September 8, 2024 How to loop through an enum in SwiftUI?

In SwiftUI, looping through an enum is not directly possible without some extra work because enums in Swift don’t inherently support iteration. However, you can achieve this by making the enum CaseIterable, which automatically provides a collection of all cases in the enum.

question swiftui swift September 13, 2024 How to add a character limit to a TextField in SwiftUI?

To add a character length limit to a TextField in SwiftUI, you can use a combination of Swift’s .onChange, .onPasteCommand modifier, and string manipulation to limit the number of characters the user can enter.

question swiftui March 29, 2024 How to group different style modifiers and reuse them across multiple SwiftUI views?

In SwiftUI, you can create custom view modifiers to encapsulate common styling configurations and reuse them across different views. Here’s how you can create and reuse a custom view modifier: