venky
venky

Reputation: 1185

How do I change scrollview's scroll direction in SwiftUI?

I was trying to implement vertical scroll with image and text but I am not able to achieve it.

I tried on both Xcode beta 1 & 2. Here is the code snippet

Upvotes: 0

Views: 532

Answers (1)

Bogdan Farca
Bogdan Farca

Reputation: 4106

Try to wrap both the Text and the Image in a VStack and be sure that there is enough content inside the ScrollView to fall outside it's bounds (in the right direction - vertically in your case):

ScrollView {
    VStack {
        ForEach (1...100) {_ in
            Image(systemName: "circle.fill")
            Text("my text")
        }
    }
}

You could easily try it out in a Playground like this :

import SwiftUI
import PlaygroundSupport

struct LiveView : View {
    var body: some View {
        ScrollView {
            VStack {
                ForEach (1...100) {_ in
                    Image(systemName: "circle.fill")
                    Text("Some text")
                }
            }
        }
    }
}

PlaygroundPage.current.liveView = UIHostingController(rootView: LiveView())

Upvotes: 1

Related Questions