Ios 如何在SwiftUI中创建具有顶部(行标题/第一行)和侧面(第一列)的固定视图
我正在尝试创建第一行和第一列固定的视图。我可以使用Ios 如何在SwiftUI中创建具有顶部(行标题/第一行)和侧面(第一列)的固定视图,ios,swift,swiftui,Ios,Swift,Swiftui,我正在尝试创建第一行和第一列固定的视图。我可以使用LazyVStack(对齐:.center,间距:10,pinnedViews:[.sectionHeaders])创建第一行固定视图,或者使用LazyHStack(对齐:.center,间距:10,pinnedViews:[.sectionHeaders])固定第一列(对齐:.center,间距:10,pinnedViews:[.sectionHeaders])。你知道如何在SwiftUI中做到这一点吗。我在网上查找,但找不到使用SwiftUI
LazyVStack(对齐:.center,间距:10,pinnedViews:[.sectionHeaders])
创建第一行固定视图,或者使用LazyHStack(对齐:.center,间距:10,pinnedViews:[.sectionHeaders])
固定第一列(对齐:.center,间距: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)
}
}
struct ContentView:View{
私有变量颜色:[Color]=[.blue、.yellow、.green]
私有变量gridItems=Array(重复:GridItem(.fixed(50)),计数:10)
var body:一些观点{
滚动视图(.horizontal){
LazyHGrid(行:gridItems,间距:5,固定视图:[.sectionHeaders]){
章节(标题:标题视图(1)){
ForEach((0..<10),id:\.self){idx in
ForEach((0..some视图{
文本(“节\(索引)”)
.padding()
.foregroundColor(颜色.白色)
.font(.title)
.frame(最大高度:。无穷大)
.背景(颜色.蓝色)
}
}