Unstyled, non looped, vertical scrolling in SwiftUI

Hi all,


I'm looking for a way to vertically scroll several grouped elements in a VStack. If I use List, it places everything in Table cells, (which I don't want). Wrapping everything in ScrollView, automatically expands all my VStacked elements beyond the screen width. Is there currently any way with ScrollView to respect the screen's width, and only scroll vertically?


In a nutshell, I'm trying to mimic a one column UICollectionView. Not styled like a table, but smooth vertical-only scrolling.


- Scott

Replies

You can limit the width of a element (in your case ScrollView or the VStack) using the GeometryReader.


var body: some View {
        return GeometryReader { geometry in
            ScrollView {
                VStack {
                    [...]
                }
                .frame(width: geometry.size.width)
            }
        }
    }