Skip to content

Instantly share code, notes, and snippets.

@yannxou
Created October 29, 2025 15:09
Show Gist options
  • Select an option

  • Save yannxou/1a62607d3805fc531fcb999e7ea935c2 to your computer and use it in GitHub Desktop.

Select an option

Save yannxou/1a62607d3805fc531fcb999e7ea935c2 to your computer and use it in GitHub Desktop.
SwiftUI: Scroll only when content does not fit
// source: https://fatbobman.com/en/posts/mastering-viewthatfits/
var body: some View {
VStack(alignment:.leading) {
Text("Count: \(count)")
Slider(value: $step, in: 3 ... 20, step: 1)
ViewThatFits {
content
ScrollView(.horizontal,showsIndicators: true) {
content
}
}
}
.frame(width: 300)
.border(.red)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment