Created
October 23, 2024 16:26
-
-
Save takoikatakotako/334b1ca0d6d414776c06f0b174fcd057 to your computer and use it in GitHub Desktop.
SwiftUIでViewを横スクロールで表示する
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 { | |
| 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