TapGesture

Tappable Views (Image, Text, Anything)

Usage

Rectangle()
    .foregroundColor(.orange)
    .frame(width: 100, height: 100)
    .gesture(
        TapGesture(count: 1).onEnded {
            // Action
        }
    )
    
// Much easier one,
// we can use .onTapGesture directly on a view
Rectangle()
    .foregroundColor(.orange)
    .frame(width: 100, height: 100)
    .onTapGesture {
        // Action    
    }

TapGesture is usable for every View

Last updated