Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a vertical ScrollView in SwiftUI.
iOS Swift
ScrollView([1]) { Text("Hello, ScrollView!") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .horizontal when vertical scrolling is needed.
Omitting the axis parameter causes a default vertical scroll.
✗ Incorrect
The ScrollView direction is set using .vertical to scroll vertically.
2fill in blank
mediumComplete the code to add padding inside the ScrollView content.
iOS Swift
ScrollView(.vertical) {
Text("Scrollable content")
.[1](20)
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using margin which is not a SwiftUI modifier.
Using frame which changes size but not inner spacing.
✗ Incorrect
Use padding(20) to add space inside the content area.
3fill in blank
hardFix the error in the ScrollView code to make it compile.
iOS Swift
ScrollView(.vertical) {
VStack {
Text("Item 1")
Text("Item 2")
}[1]
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .scrollable() which does not exist in SwiftUI.
Using .frame() without parameters may not fix the error.
✗ Incorrect
Adding .padding() after VStack is valid and compiles correctly.
4fill in blank
hardFill both blanks to create a horizontal ScrollView with spacing between items.
iOS Swift
ScrollView([1]) { HStack(spacing: [2]) { Text("A") Text("B") Text("C") } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .vertical axis with HStack causes no horizontal scroll.
Using spacing as a modifier instead of a parameter.
✗ Incorrect
Use .horizontal for horizontal scrolling and 10 for spacing between items.
5fill in blank
hardFill all three blanks to create a ScrollView with a VStack that has padding and a background color.
iOS Swift
ScrollView(.vertical) {
VStack {
Text("Hello")
Text("World")
}[1]([2])
.[3](Color.gray.opacity(0.2))
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using frame instead of padding for spacing.
Using background without parentheses.
✗ Incorrect
Use padding(30) to add space inside VStack and background to set a light gray background color.