SwiftUI Button Action is not working but OnTapGesture

Viewed 4023

Hello I am trying to achieve simple functionality but somehow I am unable to use action of button, it never triggered, and not only in this code but also in my entire application, Am I doing something wrong or is it a glitch from SwiftUI. But onTapGesture works perfectly.

struct CounterView: View {
@State var counter = 0

var body: some View{

    HStack(alignment: .center, spacing: 8){
        Button(action: {
            //self.counter += 1
            }) {
            HStack {
                Image(systemName: "plus")
            }.padding(4.0)
            .overlay(
                RoundedRectangle(cornerRadius: 4.0)
                    .stroke(lineWidth: 1.0)
                .trim()
            )
                .onTapGesture {
                    self.counter += 1
                }
        }}}

Help me resolve this issue.

1 Answers

You need to set a size on the image

Image(systemName: "plus")
    .font(.system(size: 40, weight: .regular))
Related