I'm looking to create RadioButton like buttons inside a form that the user can select Yes / No - (true / false).
As of right now, a screen shot and code is below:
So far, I pretty much have the button code and nothing Binded
to these two buttons yet.
Section("test button Yes No") {
HStack {
Spacer()
Button(action: {
}, label: {
Image(systemName: "circle")
.renderingMode(.original)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 18, height: 18)
})
.padding(10)
Button(action: {
}, label: {
Image(systemName: "circle")
.renderingMode(.original)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 18, height: 18)
})
}
}
A couple things I'd like to do:
- Connect these two buttons to a Bool() - Maybe it should be a group and not separate?
- Can only select one at a time. 2a. an OnTapGesture to change button to be a fill when selected.
I do have a couple of custom button styles that are NOT connected to the code yet but thought I'd show these in case additional information is needed. Two different styles, a My ButtonStyle,
and a MyButtonPressed
style
struct MyButtonStyle: ButtonStyle {
func makeBody(configuration: Self.Configuration) -> some View {
configuration.label
.padding()
.foregroundColor(.white)
.background(configuration.isPressed ? Color.red : Color.blue)
.cornerRadius(8.0)
}
}
struct MyButtonPressed: ButtonStyle {
func makeBody(configuration: Self.Configuration) -> some View {
configuration.label
.padding()
.foregroundColor(.white)
.background(configuration.isPressed ? Color.red : Color.blue)
.cornerRadius(8.0)
}
}
Thanks!
If you need any additional info, please ask.