To style a button in SwiftUI, according to my understanding, you extend ButtonStyle
and implement func makeBody(configuration: Self.Configuration) -> s
You can merge the disabled status into the buttonStyle, so that you will not used it twice in the application.
struct CustomizedButtonStyle : PrimitiveButtonStyle {
var disabled: Bool = false
func makeBody(configuration: Self.Configuration) -> some View {
configuration.label.disabled(disabled)
.overlay(
RoundedRectangle(cornerRadius: 4).stroke(disabled ? Color.blue : Color.gray, lineWidth: 1).padding(8)
)
}
}
struct ButtonUpdate: View {
var body: some View {
VStack{
Button(action: {
}) { Text("button")
}.buttonStyle(CustomizedButtonStyle(disabled: true))
Button(action: {
}) { Text("button")
}.buttonStyle(CustomizedButtonStyle())
}}
}