UICollectionView and SwiftUI?

后端 未结 16 1461
时光说笑
时光说笑 2020-12-02 07:32

How to create grid of square items (for example like in iOS Photo Library) with SwiftUI?

I tried this approach but it doesn\'t work:

var body: some          


        
16条回答
  •  死守一世寂寞
    2020-12-02 08:01

    Try using a VStack and HStack

    var body: some View {
        GeometryReader { geometry in
            VStack {
                ForEach(1...3) {_ in
                    HStack {
                        Color.orange.frame(width: 100, height: 100)
                        Color.orange.frame(width: 100, height: 100)
                        Color.orange.frame(width: 100, height: 100)
                    }.frame(width: geometry.size.width, height: 100)
                }
            }
        }
    }
    

    You can wrap in a ScrollView if you want scrolling

提交回复
热议问题