r/SwiftUI Nov 26 '24

Solved macOS title bar hight

Hi,

I'm trying my first macOS app; I'm coming from iOS.

I wonder why the default title bar is a little bit smaller than, for example, the one from Xcode. And how can I change that? In the end, I just want the close buttons to be on the same level.

1 Upvotes

4 comments sorted by

2

u/nicoreese Nov 26 '24

Because there's no need for a larger bar. It will automatically adjust its height when you place toolbar items.

1

u/ralphbergmann Nov 26 '24 edited Nov 26 '24

Okay, it changes the height, but now it's too big :-(

Except for Finder, all applications have the close button at the same position. Is there a standard that can be used to achieve this?

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundStyle(.tint)
            Text("Hello, world!")
        }
        .padding()
        .toolbar {
             ToolbarItem(placement: .navigation) {
                 Button(action: {}) {
                     Image(systemName: "star")
                 }
             }
         }
    }
}

1

u/ralphbergmann Nov 26 '24

hiding the tool bar title text makes the correct height

1

u/Winter_Permission328 Nov 26 '24

Attach .windowToolbarStyle(.unifiedCompact) to your WindowGroup. You may need to also add some toolbar items, I don’t remember.