Geo*_*nts 8 user-interface swift swiftui
我想创建带有标题和一些单元格的自定义下拉部分。基本上,我希望单元格与我的标题具有相同样式(页脚中所有单元格的宽度/白色背景/阴影相同)。问题是:

内容视图
var body: some View {
ScrollView{
VStack(alignment: .center, spacing: 0){
VStack{
Text("")
.foregroundColor(.white)
.fixedSize(horizontal: false, vertical: true)
Image("")
.renderingMode(.template)
.resizable()
.aspectRatio(contentMode: .fit)
.foregroundColor(Color.white)
.frame(width: 40, height: 40, alignment: .center)
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 330, maxHeight: 330)
.background(Color.darkBlue)
TestView() //HERE IS CELL VIEW
.frame(minWidth: 0, maxWidth: .infinity, minHeight: UIScreen.main.bounds.height - 330, maxHeight: UIScreen.main.bounds.height - 330)
}
.padding(.horizontal, 0)
.padding(.top, -20)
.navigationBarTitle("")
.navigationBarHidden(true)
}
}
Run Code Online (Sandbox Code Playgroud)
测试视图
var body: some View {
List {
ForEach(viewModel.latinities) { (section) in
Section(header: HeaderView(section: section)
//.background(Color.white)
.clipped()
.cornerRadius(10)
.shadow(color: Color(#colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.1)), radius: 5, x: 1, y: 5)
.onTapGesture {
self.viewModel.latinities[self.sectionIndex(section: section)].expanded.toggle()
}, footer: EmptyView()) {
if !section.expanded {
ForEach(section.quotes) { (quote) in
QuoteViews(quote: quote)
.background(Color.red)
.cornerRadius(10)
.onTapGesture {
let sectionIndex = self.sectionIndex(section: section)
let quoteIndex = self.quoteIndex(section: sectionIndex, quote: quote)
self.viewModel.latinities[sectionIndex].quotes[quoteIndex].expanded.toggle()
}
}
}
}
}
}
.onAppear { UITableView.appearance().separatorStyle = .none }
.onDisappear { UITableView.appearance().separatorStyle = .singleLine }
.background(Color.blue)
.listStyle(GroupedListStyle())
}
Run Code Online (Sandbox Code Playgroud)
消除您需要的间距
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
Run Code Online (Sandbox Code Playgroud)
调用部分块和单元块的 。像这样的东西:
Section(header: HeaderView(section: section)
//.background(Color.white)
.clipped()
.cornerRadius(10)
.shadow(color: Color(#colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.1)), radius: 5, x: 1, y: 5)
.onTapGesture {
self.viewModel.latinities[self.sectionIndex(section: section)].expanded.toggle()
}, footer: EmptyView()) {
if !section.expanded {
ForEach(section.quotes) { (quote) in
QuoteViews(quote: quote)
.background(Color.red)
.cornerRadius(10)
.onTapGesture {
let sectionIndex = self.sectionIndex(section: section)
let quoteIndex = self.quoteIndex(section: sectionIndex, quote: quote)
self.viewModel.latinities[sectionIndex].quotes[quoteIndex].expanded.toggle()
}.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
}
}
}.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4719 次 |
| 最近记录: |