---
title: TapGesture
framework: swiftui
role: symbol
role_heading: Structure
path: swiftui/tapgesture
---

# TapGesture

A gesture that recognizes one or more taps.

## Declaration

```swift
nonisolated struct TapGesture
```

## Overview

Overview To recognize a tap gesture on a view, create and configure the gesture, and then add it to the view using the gesture(_:including:) modifier. The following code adds a tap gesture to a Circle that toggles the color of the circle: struct TapGestureView: View {     @State private var tapped = false

var tap: some Gesture {         TapGesture(count: 1)             .onEnded { _ in self.tapped = !self.tapped }     }

var body: some View {         Circle()             .fill(self.tapped ? Color.blue : Color.red)             .frame(width: 100, height: 100, alignment: .center)             .gesture(tap)     } }

## Topics

### Creating a tap gesture

- [init(count:)](swiftui/tapgesture/init(count:).md)
- [init(count:inputKinds:)](swiftui/tapgesture/init(count:inputkinds:).md)
- [count](swiftui/tapgesture/count.md)

## Relationships

### Conforms To

- [Gesture](swiftui/gesture.md)

## See Also

### Recognizing tap gestures

- [onTapGesture(count:perform:)](swiftui/view/ontapgesture(count:perform:).md)
- [onTapGesture(count:coordinateSpace:perform:)](swiftui/view/ontapgesture(count:coordinatespace:perform:).md)
- [onTapGesture(count:coordinateSpace:inputKinds:perform:)](swiftui/view/ontapgesture(count:coordinatespace:inputkinds:perform:).md)
- [SpatialTapGesture](swiftui/spatialtapgesture.md)
