Skip to content

Commit ca99a80

Browse files
cilippofiliayangc95KTom101
authored
SwiftUI Entry: Scrollview (#1290)
* List image for new PR * SwiftUI View: ScrollView * Update content/swiftui/concepts/views/terms/scrollview/scrollview.md Co-authored-by: Christine Yang <[email protected]> * Updated pseudocode Up to date pseudocode reflecting the comments received. * Updated ScrollView Example Up to date scroll view example following the suggestion and comments received * Scrollview PR gif * Delete list.png * Updated code snippet to reflect gif * Update content/swiftui/concepts/views/terms/scrollview/scrollview.md Co-authored-by: Christine Yang <[email protected]> * Update content/swiftui/concepts/views/terms/scrollview/scrollview.md Co-authored-by: Christine Yang <[email protected]> * Update content/swiftui/concepts/views/terms/scrollview/scrollview.md Co-authored-by: Christine Yang <[email protected]> * Update examples as per comments received * Update scrollview.md * Update scrollview.md * Delete scrollviews.gif * new gifs related to each scrollview example * Update scrollview.md * Delete swiftui-scrollview-vertical.gif * Delete swiftui-scrollview-horizontal.gif * Adding cropped versions of gif * updated names to match files * Update content/swiftui/concepts/views/terms/scrollview/scrollview.md Co-authored-by: KTom101 <[email protected]> * Update content/swiftui/concepts/views/terms/scrollview/scrollview.md Co-authored-by: KTom101 <[email protected]> * Add example 2 header and run scripts Co-authored-by: Christine Yang <[email protected]> Co-authored-by: KTom101 <[email protected]>
1 parent 7086e8d commit ca99a80

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
Title: 'ScrollView'
3+
Description: 'Scrollable view within the scrollable content region.'
4+
Subjects:
5+
- 'Mobile Development'
6+
- 'Computer Science'
7+
Tags:
8+
- 'SwiftUI'
9+
- 'SwiftUI Views'
10+
- 'Views'
11+
- 'Xcode'
12+
CatalogContent:
13+
- 'learn-swift'
14+
- 'paths/build-ios-apps-with-swiftui'
15+
---
16+
17+
The **`ScrollView`** displays content within the scrollable content region. Based on platform appropriate scroll gestures, or how the code works, the view can scroll vertically, horizontally, or both.
18+
19+
## Syntax
20+
21+
```pseudo
22+
var body: some View {
23+
ScrollView(.horizontal) {
24+
Subviews here
25+
}
26+
}
27+
```
28+
29+
The `ScrollView` view rests within the body of a `View`. It can accept two parameters:
30+
31+
- `.vertical` which is usually the standard if not specified.
32+
- `.horizontal` which makes the view scroll horizontally.
33+
34+
## Example 1
35+
36+
In the first example below, the `ScrollView` scrolls vertically and contains a `LazyHStack` that consists of rows stacked on top of each other in the view:
37+
38+
```swift
39+
var body: some View {
40+
ScrollView(.vertical) {
41+
LazyVStack {
42+
ForEach(0 ... 10, id: \.self) {
43+
Text("Row \($0)")
44+
}
45+
}
46+
}
47+
```
48+
49+
This will display the following:
50+
51+
![Vertical ScrollView](https://raw.githubusercontent.com/Codecademy/docs/main/media/swiftui-scrollview-vertical.gif)
52+
53+
## Example 2
54+
55+
In this example, the `ScrollView` scrolls horizontally and contains a `LazyHStack` that consists of columns stacked next to each other in the view:
56+
57+
```swift
58+
var body: some View {
59+
ScrollView(.horizontal) {
60+
LazyHStack {
61+
ForEach(0 ... 10, id: \.self) {
62+
Text("Row \($0)")
63+
}
64+
}
65+
}
66+
```
67+
68+
`ScrollView()` displays the content within the scrollable region and adjusts what portion of the content is visible. Here, the axis is set to `.horizontal`, which allows for horizontal scrolling. `ScrollView()` natively will scroll vertically and the paramenter inside the brackets can be omitted.
69+
70+
This will display the following:
71+
72+
![Horizontal ScrollView](https://raw.githubusercontent.com/Codecademy/docs/main/media/swiftui-scrollview-horizontal.gif)
36.8 KB
Loading
35.3 KB
Loading

0 commit comments

Comments
 (0)