UICollectionView and SwiftUI?

后端 未结 16 1447
时光说笑
时光说笑 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 07:41

    I think you can use scrollview like this

    struct MovieItemView : View {
        var body: some View {
            VStack {
                Image("sky")
                    .resizable()
                    .frame(width: 150, height: 200)
                VStack {
                    Text("Movie Title")
                        .font(.headline)
                        .fontWeight(.bold)
                    Text("Category")
                        .font(.subheadline)
                }
            }
        }
    }
    
    struct MoviesView : View {
        var body: some View {
            VStack(alignment: .leading, spacing: 10){
                Text("Now Playing")
                    .font(.title)
                    .padding(.leading)
                ScrollView {
                    HStack(spacing: 10) {
                        MovieItemView()
                        MovieItemView()
                        MovieItemView()
                        MovieItemView()
                        MovieItemView()
                        MovieItemView()
                    }
                }
                .padding(.leading, 20)
            }
        }
    }
    

提交回复
热议问题