Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a SwiftUI view Scrollable?

Tags:

ios

swiftui

How do I make my Body View as Scrollable?

I need to make the large Lorem ipsum text scrollable.

struct FeatureDetail : View {
    var body: some View {  
       //Scrollable {  Does Not work
        VStack{
            Image("wwdc")
                .resizable()
                .aspectRatio(contentMode: .fit)
                .padding()

            Text("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.").lineLimit(nil).padding(20)

            }.navigationBarTitle(Text("WWDC"), displayMode:.automatic)
       //}
    }
}        
like image 550
Mayur Tolani Avatar asked Jun 08 '19 05:06

Mayur Tolani


People also ask

How do I use scroll view in Swift?

1. Add scrollView(1) in storyboard, add needed constraint to top/bottom/trailing/leading. 2. Then uncheck "Content Layout Guides" in Size inspector section for your scrollView.

How do I use scroll view?

In Android, a ScrollView is a view group that is used to make vertically scrollable views. A scroll view contains a single direct child only. In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it.


1 Answers

You can use List instead of ScrollView to enable scrolling. Wrap your content in a List:

List {
  VStack{
    Image("wwdc")
      .resizable()
      .aspectRatio(contentMode: .fit)
      .padding()

    Text("Very long text").lineLimit(nil).padding(20)

  }.navigationBarTitle(Text("WWDC"), displayMode:.automatic)
}
like image 180
M Reza Avatar answered Sep 28 '22 09:09

M Reza