A ScrollView is a container that lets users scroll through content that is larger than the visible screen area. It allows vertical, horizontal, or both directions of scrolling.
Click to reveal answer
beginner
How do you add content inside a ScrollView in SwiftUI?
You place the content views inside the ScrollView's closure. For example: ScrollView { VStack { Text("Hello") Text("World") } }
Click to reveal answer
intermediate
What property controls the scrolling direction in SwiftUI's ScrollView?
The 'axes' parameter controls direction. Use .vertical for vertical scrolling, .horizontal for horizontal scrolling, or [.vertical, .horizontal] for both.
Click to reveal answer
beginner
Why should you use ScrollView instead of a fixed container for long content?
Because ScrollView lets users see all content by scrolling, avoiding content being cut off on small screens or when content is dynamic and long.
Click to reveal answer
intermediate
How can you make a ScrollView accessible for users with disabilities?
Use accessibility modifiers like .accessibilityLabel and ensure content inside is readable by screen readers. Also, keep scrolling smooth and predictable.
Click to reveal answer
Which SwiftUI view allows content to be scrollable?
AText
BVStack
CButton
DScrollView
✗ Incorrect
ScrollView is the view that enables scrolling of its child content.
How do you specify vertical scrolling in a ScrollView?
AScrollView(.vertical) { ... }
BScrollView(.horizontal) { ... }
CScrollView(.both) { ... }
DScrollView() { ... }
✗ Incorrect
Use .vertical as the axes parameter to enable vertical scrolling.
What happens if content inside a ScrollView is smaller than the screen?
AScrollView scrolls anyway
BNo scrolling occurs; content fits on screen
CContent is clipped
DScrollView crashes
✗ Incorrect
If content fits, ScrollView does not scroll and shows all content.
Which layout container is commonly used inside ScrollView for vertical stacking?
AZStack
BHStack
CVStack
DList
✗ Incorrect
VStack stacks views vertically and is often used inside vertical ScrollViews.
To improve accessibility, what should you add to ScrollView content?
AAccessibility labels and hints
BBackground colors
CAnimations
DExtra padding
✗ Incorrect
Accessibility labels and hints help screen readers describe content.
Explain how to create a vertical ScrollView in SwiftUI and add multiple text items inside it.
Think about wrapping a VStack inside ScrollView.
You got /4 concepts.
Describe why ScrollView is important for mobile apps and how it improves user experience.
Imagine reading a long list or article on a phone.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using a ScrollView in an iOS app?
easy
A. To create buttons that respond to taps
B. To allow users to scroll content that is larger than the screen
C. To display images without interaction
D. To change the app's background color
Solution
Step 1: Understand ScrollView's role
A ScrollView lets users move through content that doesn't fit on the screen at once.
Step 2: Compare options
Only To allow users to scroll content that is larger than the screen describes scrolling content, which is the ScrollView's purpose.
Final Answer:
To allow users to scroll content that is larger than the screen -> Option B
Quick Check:
ScrollView = scroll content [OK]
Hint: ScrollView enables scrolling for big content [OK]
Common Mistakes:
Thinking ScrollView creates buttons
Confusing ScrollView with static image display
Assuming ScrollView changes colors
2. Which of the following is the correct way to create a vertical ScrollView in SwiftUI?
easy
A. ScrollView(.vertical) { Text("Hello") }
B. ScrollView(.horizontal) { Text("Hello") }
C. ScrollView(vertical) { Text("Hello") }
D. ScrollView(.diagonal) { Text("Hello") }
Solution
Step 1: Recall ScrollView initializer
ScrollView takes a parameter for scroll direction: .vertical or .horizontal.
Step 2: Identify correct direction
.vertical is for vertical scrolling, so ScrollView(.vertical) { Text("Hello") } is correct. ScrollView(.diagonal) { Text("Hello") } uses invalid .diagonal.
Final Answer:
ScrollView(.vertical) { Text("Hello") } -> Option A
Quick Check:
Vertical scroll = .vertical [OK]
Hint: Use .vertical for vertical scrolling in ScrollView [OK]
Common Mistakes:
Using .diagonal which is not valid
Confusing .horizontal with vertical
Using incorrect syntax like ScrollView(vertical)
3. What will be the visible result of this SwiftUI code?
5. You want to create a ScrollView that scrolls both vertically and horizontally to show a grid of colored squares. Which SwiftUI code snippet correctly achieves this?
hard
A. ScrollView(.horizontal) { LazyVGrid(columns: Array(repeating: GridItem(), count: 3)) { ForEach(0..<9) { i in Rectangle().fill(Color.red).frame(width: 50, height: 50) } } }
B. ScrollView(.vertical) { LazyHGrid(rows: Array(repeating: GridItem(), count: 3)) { ForEach(0..<9) { i in Rectangle().fill(Color.red).frame(width: 50, height: 50) } } }
C. ScrollView([.vertical, .horizontal]) { LazyVGrid(columns: Array(repeating: GridItem(), count: 3)) { ForEach(0..<9) { i in Rectangle().fill(Color.red).frame(width: 50, height: 50) } } }
D. ScrollView() { VStack { ForEach(0..<9) { i in Rectangle().fill(Color.red).frame(width: 50, height: 50) } } }
Solution
Step 1: Understand ScrollView directions
To scroll both vertically and horizontally, pass [.vertical, .horizontal] as directions.
Step 2: Use grid layout inside ScrollView
LazyVGrid with columns creates a grid that scrolls vertically and horizontally if inside a ScrollView with both directions.
Step 3: Check other options
Options B and C use only one scroll direction or wrong grid type. ScrollView() { VStack { ForEach(0..<9) { i in Rectangle().fill(Color.red).frame(width: 50, height: 50) } } } uses VStack without scrolling horizontally.
Final Answer:
ScrollView([.vertical, .horizontal]) { LazyVGrid(columns: Array(repeating: GridItem(), count: 3)) { ForEach(0..<9) { i in Rectangle().fill(Color.red).frame(width: 50, height: 50) } } } -> Option C
Quick Check:
Both directions + LazyVGrid = scroll grid [OK]
Hint: Use ScrollView([.vertical, .horizontal]) for 2D scrolling [OK]
Common Mistakes:
Using only one scroll direction for 2D scroll
Mixing LazyHGrid with vertical scroll
Not wrapping grid in ScrollView
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.