TransmissionsDev
TransmissionsDev

Reputation: 398

SwiftUI SF Symbols Button in NavigationBar not working

I'm trying to use a button that is a SF Symbol Image as the trailing navigation bar item, however, when clicking the button on a REAL IPHONE, it's very very unreliable and I end up clicking it 30+ to only get 1 click registered.

My code looks like this:

NavigationView {
            List {
                Text("Example")
            } .navigationBarTitle("Tasks").navigationBarItems(trailing:

            Button(action: { print("I was clicked!")}) {
                Image(systemName: "plus")
            }

            )
}

However, when I put the same button outside of navigationBarItems, the button registers clicks much easier.

What can I do here?

Is this a problem with SwiftUI, if so, is there a workaround?

Thanks!

Upvotes: 3

Views: 3106

Answers (1)

sfung3
sfung3

Reputation: 2387

You can add padding to the image to increase the hitbox of the image

Image(systemName: "plus")
    .padding([.leading, .top, .bottom])

Upvotes: 2

Related Questions