Swift ScrollViewのスクロール方向を横向きにするサンプル

環境
Swift version 5.2.3 (swift-5.2.3-RELEASE)
Ubuntu 20.04.2 LTS

構文
ScrollView (.horizontal) {
//要素コード
}
ScrollViewの引数に「.horizontal」を指定します。
ScrollViewの引数に「.horizontal」を指定することで、スクロール方向を横にします。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
struct ContentView: View {
var body: some View {
ScrollView (.horizontal){
HStack {
ForEach(0..<10, id: \.self) { index in
Text("Product \(index)")
.padding()
}
}
}
}
}
struct ContentView: View { var body: some View { ScrollView (.horizontal){ HStack { ForEach(0..<10, id: \.self) { index in Text("Product \(index)") .padding() } } } } }
struct ContentView: View {
    var body: some View {
        ScrollView (.horizontal){
            HStack {
                ForEach(0..<10, id: \.self) { index in
                    Text("Product \(index)")
                        .padding()
                }
            }
        }
    }
}

 

Swift

Posted by arkgame