Created
October 23, 2024 16:14
-
-
Save takoikatakotako/e9740068088e45750fd7480bd6ae0d38 to your computer and use it in GitHub Desktop.
SwiftUIのListでSpacerの部分にもタップ判定をつける
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct ContentView: View { | |
| let pokemons: [String] = ["Snorlax", "Pikachu", "Slowpoke"] | |
| var body: some View { | |
| List(pokemons, id: \.self) {pokemon in | |
| HStack { | |
| Text(pokemon) | |
| Spacer() | |
| } | |
| .contentShape(Rectangle()) | |
| .onTapGesture { | |
| print(pokemon) | |
| } | |
| } | |
| } | |
| } | |
| #Preview { | |
| ContentView() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment