Is it possible to explicitly set content size of ScrollView in SwiftUI (like we do in UIKit)? I tried setting frame or height of ScrollView to 10000 points but it seems to be ignored.
Is it possible to explicitly set content size of ScrollView in SwiftUI (like we do in UIKit)? I tried setting frame or height of ScrollView to 10000 points but it seems to be ignored.
2
Answers
ScrollView automatically has contentSize equal to all its child view’s sizes. So you can simply add a
Spacer
and set a frame for it. Changing the scrollView frame by itself won’t have any effect unless you put scrollView inside another View.In iOS 17+ you can use
Here is some sample code.
I would also recommend watching the related WWDC video.
https://developer.apple.com/wwdc23/10159
Prior to iOS 17 you would have to set the size manually or use the default size.