ios - 如何在 SwiftUI 中使用 Top(行标题/第一行)和 Side(第一列)创建固定视图
问题描述
我正在尝试创建一个固定第一行和第一列的视图。我可以使用固定第一行LazyVStack(alignment: .center, spacing: 10, pinnedViews: [.sectionHeaders])
或使用固定第一列LazyHStack(alignment: .center, spacing: 10, pinnedViews: [.sectionHeaders])
但不能同时使用两者来创建视图。知道如何在 SwiftUI 中执行此操作。我在网上查看,但找不到使用 SwiftUI 的解决方案。
这是我目前拥有的第一列
struct ContentView: View {
private var colors: [Color] = [.blue, .yellow, .green]
private var gridItems = Array(repeating: GridItem(.fixed(50)), count: 10)
var body: some View {
ScrollView(.horizontal) {
LazyHGrid(rows: gridItems, spacing: 5, pinnedViews: [.sectionHeaders]) {
Section(header: headerView(1)) {
ForEach((0 ..< 10), id:\.self) { idx in
ForEach((0..<10), id: \.self) { index in
CellContent(rowIndex: idx, colIndex: index,
color: colors[index % colors.count])
}
}
}
}.frame(height: 570)
.padding(5)
}
}
private func headerView(_ index: Int) -> some View{
Text("Section \(index)")
.padding()
.foregroundColor(Color.white)
.font(.title)
.frame(maxHeight: .infinity)
.background(Color.blue)
}
}
解决方案
推荐阅读
- javascript - 使用 onBoundsChanged 响应谷歌地图重新渲染问题
- html - 添加过渡图像
- php - PHP Cli - json 编码一个数组并传递给 STDIN
- html - 由于 /deep/,闪烁文本出现在所有屏幕上 - CSS
- image-processing - 正方体 image_to_string 为空
- r - 在R中总结一个逻辑向量
- regex - 正则表达式匹配域名(但不是 TLD)
- java - 尝试关闭蓝牙套接字时变为空(错误:空对象引用)
- python-3.x - 使用字典理解创建字典并为每个键分配多个值
- python-3.x - python一直说'输入未定义。我该如何解决?