0

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

venky
  • 1,155
  • 1
  • 11
  • 26
  • Possible duplicate of [SwiftUI ScrollView only scroll in one direction](https://stackoverflow.com/questions/56677633/swiftui-scrollview-only-scroll-in-one-direction) – Matteo Pacini Jun 28 '19 at 07:02

1 Answers1

1

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())
Bogdan Farca
  • 3,856
  • 26
  • 38