How do you make a Button conditionally hidden or disabled?

后端 未结 5 423
囚心锁ツ
囚心锁ツ 2021-01-12 14:08

How do I toggle the presence of a button to be hidden or not?
We have the non-conditional .hidden() property; but I need the conditional version.

Note: w

5条回答
  •  情话喂你
    2021-01-12 15:00

    I hope hidden modifier gets argument later, but since then, Set the alpha instead:

    @State var shouldHide = false
    
    var body: some View {
        Button("Button") { self.shouldHide = true }
        .opacity(shouldHide ? 0 : 1)
    }
    

提交回复
热议问题