← Back to archive

Development · SwiftUI

Scroll direction and indicators in SwiftUI

Arrange scrollable content vertically or horizontally and control the visibility of scroll indicators.

Read the Korean original on Velog ↗English translation

Development archive cover

Once content is larger than its available area, a ScrollView lets the user reach the rest. These small examples cover direction and indicator settings.

Vertical scrolling

The default direction is vertical. Combine VStack and ForEach to arrange repeated content.

ScrollView { // Vertical scroll view
	VStack {
		ForEach(0..<20) { index in
			Rectangle()
				.fill(Color.blue)
				.frame(height: 200)
		}
	}
}

Horizontal scrolling

Set the axes parameter to .horizontal to scroll sideways. Use showsIndicators to control whether the scroll indicator is visible.

// Horizontal scrolling without indicators
ScrollView(.horizontal, showsIndicators: false, content: {
	HStack {
		ForEach(0..<20) { index in
			Rectangle()
				.fill(Color.blue)
				.frame(width: 300)
		}
	}
})
← Back to archive