用动作调用SwiftUI按钮吗?

时间:2020-03-21 11:59:59

标签: swiftui swift5

我有一个这样的结构。如何通过动作调用SwiftUIButton?

struct SwiftUIButton: View{
        let action: () -> ()
        var body: some View{
            Button(action: action){Text("Tap me")}
        }
    }

1 个答案:

答案 0 :(得分:1)

在这里

    SwiftUIButton {
        // do anything here
        print(">> button tapped")
    }

相同(但只是简短的变体)
    SwiftUIButton(action: {
        // do anything here
        print(">> button tapped")
    })