【问题标题】:How to implement a horizontal table view?如何实现水平表格视图?
【发布时间】:2019-09-02 17:40:49
【问题描述】:

我正在尝试使用以下功能快速实现水平表格视图:

  • 以水平方式列出的图像
  • 左右水平滚动

请参阅附加的线框。

有人能指出我正确的方向吗?我尝试深入研究 UICollectionView 来实现这一点。

【问题讨论】:

标签: ios swift uitableview uicollectionview


【解决方案1】:

- SwiftUI

这个问题被问了很多,使用CollectionView 有很多答案。但在 SwiftUI 中,您可以使用水平的 ScrollView,其中包含水平的 Stack,如下所示:

struct CardView: View {
    var body: some View {
        Rectangle()
        .foregroundColor(.gray)
        .frame(width: 100, height: 80, alignment: .center)
        .cornerRadius(8)
    }
}

struct ContentView: View {

    var body: some View {
        VStack {
            HStack {
                Text("Categories")
                Spacer()
                Button(action: {}) { Text("More") }
            }.padding(16)
            ScrollView(.horizontal) {
                HStack(spacing: 16) {
                    ForEach(0...15, id: \.self) { _ in
                        CardView()
                    }
                }.padding(16)
            }
        }
    }
}

- 结果

请注意您可以在 本月晚些时候在 Apple 正式发布 SwiftUI 时在 UITableViewCell 中使用它。

【讨论】:

  • 这个问题似乎没有要求 SwiftUI 解决方案。
  • 使用 Swift 和 SwiftUI 寻求解决方案是用 Swift 编写的。它在 TableView 中可用。也许有帮助。 @rmaddy
  • 我不认为我支持 Swift UI。我在 v10
猜你喜欢
  • 1970-01-01
  • 2021-02-17
  • 1970-01-01
  • 2018-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多