Home > AI > IOS > SwiftUI >

disabled(_:)

Example :

struct ContentView: View {
    @State var showText: Bool = false
    @State var disableBtn1: Bool = false
    
    var body: some View {
        
        VStack {
            Button(action: {
                showText.toggle()
            }, label: {
                Text("show text")
            })
            .disabled(disableBtn1)
            
            
            if showText {
                Text("good")
            }
            
            Button(action: {
                disableBtn1.toggle()
            }, label: {
                Text("Disable the button")
            })
        }
    }
}

Leave a Reply