WWDC 2025 deal: 30% off our Swift and SwiftUI books! Learn more ...WWDC 2025 deal:30% off our Swift and SwiftUI books >>
Quick Tip Icon
Quick Tip

Enable scrolling based on content size in SwiftUI

When designing interfaces in SwiftUI, it’s often a good idea to wrap our app’s content in a scroll view, even if the content usually fits on screen. This helps ensure that users who enable larger text sizes in accessibility settings can still access all the content without layout issues, clipped views and truncated text. However, doing this introduces an unintended side effect. By default, ScrollView adds a bouncy scrolling behavior, even when the content fits entirely within the available space. This can make the interface feel oddly springy when no scrolling is actually needed.

iOS screen with default-sized text in a scroll view that bounces slightly despite content fitting the screen iPhone 16 Frame
iOS screen with large text that overflows, enabling vertical scrolling of the content iPhone 16 Frame

To address this, we can use the scrollBounceBehavior(_:axes:) modifier introduced in iOS 16.4. When we apply this modifier to a ScrollView or to a view hierarchy that contains one, and pass the basedOnSize value, SwiftUI automatically disables bounce behavior when the content fits and enables it only when scrolling is actually required.

ScrollView {
    WalkDetailView()
}
.scrollBounceBehavior(.basedOnSize)
iOS screen with default text size showing static layout without any scrolling or bounce iPhone 16 Frame
iOS screen with large text that overflows, enabling vertical scrolling of the content iPhone 16 Frame

This small adjustment helps create a more polished experience, adapting gracefully to both default and accessibility text sizes.

SwiftUI Fundamentals by Natalia Panferova book coverSwiftUI Fundamentals by Natalia Panferova book cover

WWDC 2025 offer: 30% off!$35$25

The essential guide to SwiftUI core concepts and APIs

SwiftUI Fundamentalsby Natalia Panferova

  • Explore the key APIs and design patterns that form the foundation of SwiftUI
  • Develop a deep, practical understanding of how SwiftUI works under the hood
  • Learn from a former Apple engineer who worked on widely used SwiftUI APIs
WWDC 2025 offer: 30% off!

The essential guide to SwiftUI core concepts and APIs

SwiftUI Fundamentals by Natalia Panferova book coverSwiftUI Fundamentals by Natalia Panferova book cover

SwiftUI Fundamentals

by Natalia Panferova

$35$25