# ScrollView

{% tabs %}
{% tab title="💾 程式" %}

```swift
struct ContentView: View {
    var body: some View {
        // ⭐️ horizontal scroll view (default = .vertical)
        ScrollView(.horizontal) {
            HStack(spacing: 15) {
                ForEach(0..<20) { i in
                    ZStack {
                        Color.red
                        Text("\(i)")
                    }.frame(width: 50, height: 50)
                }
            }
        }
    }
}
```

{% endtab %}

{% tab title="🖥️ 影片" %}
{% embed url="<https://youtu.be/DbvcD2pQGmE>" %}
tundsdev ⟩ ScrollView & Automatic Scrolling With ScrollViewReader In SwiftUI
{% endembed %}
{% endtab %}

{% tab title="📗 參考" %}

* [ ] Sarun ⟩ [How to use ScrollView in SwiftUI](https://sarunw.com/posts/how-to-use-scrollview-in-swiftui/)
* [ ] Michael Amundsen ⟩ [Every Screen in Your App Should Be a Scrolling View](https://lickability.com/blog/every-screen-in-your-app-should-be-a-scrolling-view/)
  {% endtab %}

{% tab title="👥 相關" %}

* [ScrollVGridForEach](/ios/swiftui/view/layout/grids/scrollvgridforeach.md) - ScrollView + [LazyVGrid](/ios/swiftui/view/layout/grids.md) + [ForEach](/ios/swiftui/view/grouping/foreach.md).
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/ios/swiftui/control/scrollview.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
