swiftui - 列表背景不变色
问题描述
我试图让行的宽度填满整个屏幕,或者使背景变白,因为我的列表周围有灰色填充或边框。我尝试了这个堆栈溢出问题 和来自github 但似乎没有任何效果,列表周围显示一个灰色边框,我不知道为什么。 看法
这是我的代码
var body: some View {
ZStack{
NavigationView{
ZStack{
VStack(spacing:15){
HStack{
//component CardView
CardSubjects(type: Text("Acreditadas"),count: Text("\(subjectVM.matters_approved)"), color: Color("LightGreen")).padding(.horizontal,1)
CardSubjects(type: Text("En curso"),count: Text("\(subjectVM.matters_studying)"), color: Color("DarkBlue")).padding(.horizontal,1)
CardSubjects(type: Text("Atrasadas"),count: Text("\(subjectVM.matters_pending)"), color: Color("DarkYellow")).padding(.horizontal,1)
CardSubjects(type: Text("Reprobadas"),count: Text("\(subjectVM.matters_failed)"), color: Color("DarkRed")).padding(.horizontal,1)
}
VStack{
List{
ForEach(subjectVM.classData){ data in
VStack(alignment: .leading,spacing: 10){
HStack {
Text("\(String(format: "%.1f", data.rating)) \(data.key)")
.font(.body)
.font(.system(size: 12))
.foregroundColor(Color("DarkPink"))
}
HStack {
Text(data.name)
.font(.body)
.font(.system(size: 18))
.foregroundColor(Color.black)
}
HStack{
Image(systemName: "minus").resizable()
.foregroundColor(self.subjectVM.setColorList(type: data))
.frame(width:70,height: 5)
}
}
}.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
}
}.padding(.top,40)
.overlay(DropDownSubject{ value in
self.subjectVM.SetSelect(index: value)
}.padding(.top,-15),alignment: .topLeading)
.padding(.trailing,0)
Spacer()
}.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
.background(Color.green)
.overlay(VStack{
if subjectVM.subjectFlag{
ActivityIndicator(shouldAnimate: self.$stateLoad).frame(width:100,height:100)
}
})
// FloatMenu(router: self.Router)
}.background(Color.darkYellow)
.alert(isPresented: $subjectVM.alertState, content: { self.alert })
.navigationBarTitle(self.textTitle)
.navigationBarItems(
leading:
HStack {
Button(action: {
self.Router.currentPage = "main"
}, label: {
Image(systemName: "arrow.left").font(.system(size: 25)).foregroundColor(Color("DarkPink"))
})
},
trailing:
HStack{
Button(action: {
print("Help menu")
}, label: {
Image(systemName: "questionmark.circle").font(.system(size: 25)).foregroundColor(Color("DarkPink"))
})
})
}
FloatMenu(router: self.Router)
}
}
解决方案
嵌入在 a 中的列表的默认样式NavigationView
是DefaultListStyle
/ InsetGroupedListStyle
,其中包括灰色边框。要删除样式,只需附加PlainListStyle()
到您的列表。
List {
...
}
.listStyle(PlainListStyle())
结果:
推荐阅读
- maven - jmeter 负载测试后的电子邮件摘要报告
- android - 具有网格布局的回收器视图/项目未显示,而 LayoutManager 具有高度和宽度,并且 getItemCount 返回正确的项目数
- iis - 使用 IIS 从家庭网络上的多台计算机访问该站点
- linux - 如何将代码从 Linux 服务器提交到 SVN?
- python - 需要字符串参数,在 buffer.write 中得到“字节”
- android - 测试 SD 卡是否正确安装且可写
- javascript - 如何在 extjs 应用控制器中控制事件监听器的范围
- bluetooth - SDK不可用时通过蓝牙连接自定义设备
- vbscript - 并发调用脚本后将错误值写入日志文件
- javascript - 在 OpenLayers 和 Thymeleaf 中使用 Javascript 变量