我有一个这样的结构。如何通过动作调用SwiftUIButton?
struct SwiftUIButton: View{
let action: () -> ()
var body: some View{
Button(action: action){Text("Tap me")}
}
}
答案 0 :(得分:1)
在这里
SwiftUIButton {
// do anything here
print(">> button tapped")
}
与
相同(但只是简短的变体) SwiftUIButton(action: {
// do anything here
print(">> button tapped")
})