Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save takoikatakotako/d6341beed26e10e95b1fd0a41611da8a to your computer and use it in GitHub Desktop.
SwiftUIのListの中にボタンを複数設置する
import SwiftUI
struct ContentView: View {
let pokemons: [String] = ["Snorlax", "Slowpoke", "Pikachu", "Eevee"]
@State var text: String = ""
var filterdPokemons: [String] {
if text.isEmpty {
return pokemons
} else {
return pokemons.filter {$0.uppercased().contains(text.uppercased())}
}
}
var body: some View {
ScrollView {
LazyVStack {
TextField("Type your search", text: $text)
.padding(8)
.textFieldStyle(RoundedBorderTextFieldStyle())
ForEach(filterdPokemons, id: \.self) { pokemon in
VStack(alignment: .leading) {
Text(pokemon)
.padding(.leading, 12)
Divider()
}
}
}
}
}
}
#Preview {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment