0

So I've been trying to make a button that toggles a boolean variable when clicked, and here is what I have so far. How might I move/resize the button and add a statement that toggles the boolean variable named "yes"? Also, I have the line about Image("check") but I don't think it does anything and I don't know why. Any help would be appreciated!

import SwiftUI
import SDWebImage
import WebKit


struct ContentView: View {
var body: some View {
    Button(action: {

            }) {

            Image("check").resizable().frame(width: 35, height: 35)
            }.foregroundColor(.green)
  }
 }
  • Does this answer your question? [iPhone UIButton with UISwitch functionality](https://stackoverflow.com/questions/2255166/iphone-uibutton-with-uiswitch-functionality) – chinachina123 May 29 '20 at 15:38

1 Answers1

0

You can use the below code to display the toggle switch in SwiftUI

struct ContentView: View {
    @State private var showStatus = true

    var body: some View {
        VStack {
            Toggle(isOn: $showStatus) {
                Text("Show Button Status")
            }.padding()

            if showStatus {
                Text("Button is ON")
            }else{
                Text("Button is OFF")
            }
        }
    }
}