0

Input: I have a list of View where each View is a VStack of an Image and Text

Requirement: I want to display them vertical scrollable view. However, each row should have more than one of such Views (based on how many can fit). [Note that Views are not equal in size as the Text differs]. It should NOT be horizontally scrollable

Problem: How do I dynamically adjust the number of strings in a row based on how many can fit? See Image below as an example

enter image description here

Appreciate inputs and thanks in advance!

user3213210
  • 113
  • 1
  • 2
  • 9
  • What is the problem in the screenshot provided above? These are multiple rows and each row contains multiple Elements stacked in HStack. – davidev Jul 10 '20 at 18:39
  • Hi @davidev, Yes the elements within each row in the overarching VStack are in HStack. What I want to know is if there's a way to dynamically adjust the number of items within each HStack based on the screen size and the text size – user3213210 Jul 11 '20 at 18:18

1 Answers1

0

I would advice you to use LazyVGrid with adaptive type.

And here you no longer need to use List, just use the array of views

It's a new feature so it will work in ios14.0 and above

Struct MainView : View {
    private let columnGrid = {
        GridIten(.adaptive(minimum:50)) //here you can put minimum width size value unto you.
    }
    var body: some View {
       LazyVGrid(columns: columnGrid) {
        //your view with image will come here
        }
    }
 }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Reed
  • 944
  • 7
  • 15
  • Hi @Reed, thanks for your inputs. Good to know there is a possible way to do this in iOS14. I was hoping there was a way I could do this in iOS13 as well – user3213210 Jul 11 '20 at 18:15