samedi 29 août 2020

How do I use a button to change the colour of a TextField in SwiftUI?

I am currently working on an app to create a shopping list.

The view is composed of a list of HStacks, which again is composed of a checkbox and a textfield. As of now, the button only checks/unchecks the checkbox.

However, i also want the button to change the transparancy of the following textfield.

This is my current code for each element in the list:

struct Vare: View {

@State var vare: String = ""
@State var checked = false

var body: some View {
    HStack {
        ZStack {
            Button(action: {
                self.checked.toggle()
            }) {
                Image("UnCheckbox")
                .resizable()
                .frame(width: 20, height: 20)
                .padding(.leading)
            }
            
            if checked {
                Image("Checkbox")
                .resizable()
                .frame(width: 20, height: 20)
                .padding(.leading)
                
            }
        }
       TextField("Neste vare...", text: $vare)
           .frame(maxWidth: .infinity)
    }
}

}




Aucun commentaire:

Enregistrer un commentaire