Custom Button action issue


I created a custom button in a seperate swiftView file and used it anywhere i want giving it a custom label. I am not getting an idea how to define its action differently everytime. For example, I want to add two variables in one view and refresh my list in the other. I have tried .onTap modifier but it does seems to work. If anyone can help me in this it would be a great for me.

1 Like

Hi ! I see two options.

  1. You can just create a new button every time and put your custom view in the label
Button {
// any action you want 
}, label: {YourCustomButtonView()}

Or 2) you can have the whole button in your struct but you put a completion handler in it

struct MyButton: View {
    let action: () -> ()
    var body: some View {
        Button(action: action) {

Thank you… it works!

1 Like

Yayyy :slight_smile: