Skip to content

Instantly share code, notes, and snippets.

@takoikatakotako
Created October 23, 2024 16:14
Show Gist options
  • Select an option

  • Save takoikatakotako/e9740068088e45750fd7480bd6ae0d38 to your computer and use it in GitHub Desktop.

Select an option

Save takoikatakotako/e9740068088e45750fd7480bd6ae0d38 to your computer and use it in GitHub Desktop.
SwiftUIのListでSpacerの部分にもタップ判定をつける
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