Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI SF Symbols Button in NavigationBar not working

Tags:

swift

swiftui

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!

like image 978
TransmissionsDev Avatar asked Jan 24 '26 23:01

TransmissionsDev


1 Answers

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

Image(systemName: "plus")
    .padding([.leading, .top, .bottom])
like image 60
sfung3 Avatar answered Jan 28 '26 05:01

sfung3



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!