Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI - How to hide window title on macOS

Tags:

macos

swiftui

On macOS with new SwiftUI framework without AppDelegate / SceneDelegate, how do I hide the window title?

I found this article from Apple that describes how to do it for a Catalyst app but without that delegate now, how do I achieve this?

Link to article - https://developer.apple.com/documentation/uikit/mac_catalyst/removing_the_title_bar_in_your_mac_app_built_with_mac_catalyst

enter image description here

like image 971
hvkale Avatar asked Dec 03 '20 17:12

hvkale


People also ask

How do I hide status bar in SwiftUI?

Make sure your initial SwiftUI View is a Navigation view where you hide the status bar. Then if you navigate to a tab bar view or any subsequent views the status bar will be hidden.

What is WindowGroup SwiftUI?

The default implementation of a WindowGroup allows multiple instances of the window to be created (either using ⌘N , or the "Show Tab Bar" command). Each instance of a window created from a window group contains the same SwiftUI hierarchy, but maintains an independent state.

What is the title bar on Mac?

A title bar is a small strip that extends across the top of a window. It displays the title of the window and typically includes the close, minimize, and maximize buttons. In macOS, these buttons are on the left side of the title bar, while in Windows, they are on the right.

How do I add a navigation bar in SwiftUI?

To show a Navigation Bar using SwiftUI, we should use the NavigationView component that is responsible for this purpose. It requires that we provide the Content that is a View type. The Content can be anything from a text field to scrollable content. In short, it can be any SwiftUI view.

How do I open a new window in SwiftUI on macOS?

Here is how to open a new window in SwiftUI on macOS. Text ( "Hello, world!") In your App add another WindowGroup for your viewer and set it to enable handling of external launch events (an internal event in our case).

How to create a search bar in SwiftUI for macOS?

There’s no search bar in SwiftUI for macOS, only TextField. The native macOS search bar has a default magnifying glass icon and a clear button, which will take us some time to replicate it in pure SwiftUI. Or we need to use NSViewRepresentable to wrap NSSearchField.

Is SwiftUI good for apps?

Sure, there are bugs, warts and parts that simply aren’t finished yet, especially on the Mac, but overall what Apple built here is really great, and it’s so much faster to build apps with it. SwiftUI makes the hard things simple, and sometimes it makes the simple things hard.

Is there a SwiftUI way to trigger the visibility of top-level menus?

After a discussion on Twitter, there really doesn’t seem a SwiftUI-way to trigger the visibility of top-level menus. @LeoNatan suggested to drop back into AppKit, and that’s what I ended up doing: Make sure to trigger this both on app start and whenever the debug value changes: And that’s it. Toggling the menu works just as expected.


Video Answer


2 Answers

You need to use the following window style:

WindowGroup {
    ContentView()
}
.windowStyle(HiddenTitleBarWindowStyle())
like image 52
Asperi Avatar answered Nov 11 '22 06:11

Asperi


Now it's:

WindowGroup {
  ContentView()
}
.windowStyle(.hiddenTitleBar)
like image 34
Jacob White Avatar answered Nov 11 '22 05:11

Jacob White