I know how to hide the title bar with Storyboard.

But I can't do this in SwiftUI.
I want to hide the title bar and the control buttons and make a floating image view.
import SwiftUI
@main
struct TestApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}.windowStyle(.hiddenTitleBar)
}
}
try HiddenTitleBarWindowStyle()
Also, if you have SwiftUI based App @main you can use use the .windowStyle() modifier to hide the title bar and AppDelegate to hide the buttons, like so:
import SwiftUI
@main
struct MyApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
.windowStyle(HiddenTitleBarWindowStyle())
}
}
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
hideTitleBar()
}
func hideTitleBar() {
guard let window = NSApplication.shared.windows.first else { assertionFailure(); return }
window.standardWindowButton(.closeButton)?.isHidden = true
window.standardWindowButton(.miniaturizeButton)?.isHidden = true
window.standardWindowButton(.zoomButton)?.isHidden = true
}
}
And for Catalyst, the title bar could be hidden using .onAppear { } modifier and UITitleBar api:
import SwiftUI
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onAppear { hideTitleBarOnCatalyst() }
}
}
func hideTitleBarOnCatalyst() {
#if targetEnvironment(macCatalyst)
(UIApplication.shared.connectedScenes.first as? UIWindowScene)?.titlebar?.titleVisibility = .hidden
#endif
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With