Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI Xcode 12.3 can't change button size in toolbar

Tags:

ios

swift

swiftui

struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
                Text("Hi")
            }
            .navigationBarTitleDisplayMode(.inline)
            .toolbar {
                ToolbarItem(placement: .principal) {
                    Text("Title")
                        .font(.headline)
                }
                ToolbarItem(placement: .navigationBarLeading) {
                    Button(action: {}) {
                        Image(systemName: "person.circle")
                            .font(.largeTitle)
                    }
                }
            }
        }
    }
}

The .font(.largeTitle) on Image has no effect, only if I use it inside a button.

Is this a bug or am I doing something wrong?

like image 961
vdotup Avatar asked Jan 24 '23 13:01

vdotup


1 Answers

It looks like SwiftUI treats single toolbar items differently (applies their own style, size etc).

A possible workaround is to put a Button in a more complex view, as in: How to change color of ToolbarItem with navigationBarLeading placement in SwiftUI

Adapted to your example it can look like this:

ToolbarItem(placement: .navigationBarLeading) {
    HStack {
        Button(action: {}) {
            Image(systemName: "person.circle")
                .font(.largeTitle)
        }
        Text("")
    }
}
like image 160
pawello2222 Avatar answered Feb 11 '23 23:02

pawello2222