Issue #835
I usually define ButtonStyle
to encapsulate common styles related to buttons. Here we specify .frame(maxWidth: .infinity)
to let this button take the whole width as possible
struct MyActionButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.font(.headline.bold())
.foregroundColor(.white)
.frame(height: 44)
.frame(maxWidth: .infinity)
.background(Color.green)
.cornerRadius(8)
}
}
If we have 2 buttons both specifying maxWidth: .infinity
then they will be divided equally with a spacing specified by our HStack
struct ContentView: View {
@State private var showsBottomSheet: Bool = false
var body: some View {
HStack(spacing: 20) {
Button(action: {}) {
Text("Left")
}
.buttonStyle(MyActionButtonStyle())
Button(action: {}) {
Text("Right")
}
.buttonStyle(MyActionButtonStyle())
}
.padding(.horizontal, 20)
}
}
The result looks like below