Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save takoikatakotako/334b1ca0d6d414776c06f0b174fcd057 to your computer and use it in GitHub Desktop.
SwiftUIでViewを横スクロールで表示する
import SwiftUI
struct ContentView: View {
var body: some View {
let pokemons = ["pikachu", "slowpoke", "bellsprout", "ditto", "snorlax", "eevee", "magikarp"]
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(spacing: 12) {
ForEach(pokemons, id: \.self) { pokemon in
Image(pokemon)
.resizable()
.frame(width: 80, height: 80)
.background(Color(UIColor.lightGray))
}
}
.padding(.horizontal, 12)
}
.frame(height: 80)
}
}
#Preview {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment