Is there a possibility to deactivate a button in SwiftUI? Can not find anything?
I want to do a download with Alamofire and then activate the button after successful download.
You can use the .disabled
modifier. According to the documentation:
Adds a condition that controls whether users can interact with this view.
import SwiftUI
struct ContentView: View {
@State private var buttonDisabled = true
var body: some View {
Button(action: {
//your action here
}) {
Text("CLICK ME!")
}
.disabled(buttonDisabled)
}
}
#if DEBUG
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
You can set your buttonDisabled
State var to false when your download completes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With