Thanks for the quick feedback.
In your image, the text is not entirely centered but right aligned.
To clarify myself, I removed the button corner radius and add the same button to the screen center.
You can see in my attached screenshot the default text alignment is different between the two buttons.
The button text in the toolbar is obviously right aligned (The last "m" is closer to the edge than the beginning "c").
I have tried a few different ToolBarItem placements. Placements like .confirmationAction or .navigationBarTrailing, etc. all have this behaviour.
In my opinion, it should be the button not the text that gets right aligned. If this is not a bug, what is the solution to this?
import SwiftUI
struct TestView: View {
var body: some View {
NavigationView {
ZStack {
Color(.black)
.ignoresSafeArea()
Text("Hello World")
.foregroundColor(.white)
.toolbarRole(.editor)
.toolbar {
ToolbarItem(placement: .confirmationAction) {
Button(action: {print("confirm.")}) {
Text("confirm")
}
.background(.yellow)
.foregroundColor(.white)
}
}
Button(action: {print("confirm.")}) {
Text("confirm")
}
.background(.yellow)
.foregroundColor(.white)
.offset(y: 20)
}
}
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
TestView()
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: