Created
October 29, 2025 15:09
-
-
Save yannxou/1a62607d3805fc531fcb999e7ea935c2 to your computer and use it in GitHub Desktop.
SwiftUI: Scroll only when content does not fit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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