[英]Can't get view full screen in SwiftUI
I'm trying to build a very simple app in SwiftUI.我正在尝试在 SwiftUI 中构建一个非常简单的应用程序。 The first thing I want is my view to be full screen, edge to edge.
我想要的第一件事是我的视图是全屏,边缘到边缘。 Somewhere the app is adding some padding and I can't figure it out.
该应用程序在某处添加了一些填充,我无法弄清楚。
Here's my code:这是我的代码:
struct ContentView: View {
@ObservedObject var fetcher = ArticleService()
var body: some View {
List {
ForEach(fetcher.articles) { article in
VStack (alignment: .leading) {
Text(article.section)
.foregroundColor(.red)
.textCase(.uppercase)
Text(article.title)
.font(.system(size: 20))
.fontWeight(.semibold)
UrlImageView(article.image)
.padding(EdgeInsets(top: 10, leading: 0, bottom: 10, trailing: 0))
.frame(maxWidth: .infinity)
Text(article.author)
.font(.system(size: 11))
.foregroundColor(Color.gray)
}
.frame(maxWidth: .infinity)
.background(Color.white)
}
.listRowBackground(Color.gray)
.frame(maxWidth: .infinity)
}
}
And this is the result:这是结果:
Why is each element in the list not spanning the entire screen?为什么列表中的每个元素都不跨越整个屏幕? Where is the padding coming from?
填充从哪里来?
You need list row background instead您需要列表行背景
var body: some View {
List {
ForEach(fetcher.articles) { article in // << needs ForEach !!
VStack (alignment: .leading) {
Text(article.section)
.foregroundColor(.red)
.textCase(.uppercase)
Text(article.title)
.font(.system(size: 20))
.fontWeight(.semibold)
UrlImageView(article.image)
.padding(EdgeInsets(top: 10, leading: 0, bottom: 10, trailing: 0))
Text(article.author)
.font(.system(size: 11))
.foregroundColor(Color.gray)
}
.frame(maxWidth: .infinity)
}.listRowBackground(Color.red) // << here !!
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.