我正在使用List动态创建多个视图实例,但是当使用列表时,子视图左右会添加空白,我无法去除它。我尝试使用.listRowInset,但效果不明显。
我创建了一个PostView以达到所需的效果。我使用'PostsView'动态生成多个PostView实例。
我想让PostView中的图像在PostsView中触及屏幕边缘。
PostView
import SwiftUI
struct PostView: View {
var post: Post
var body: some View {
VStack {
HStack {
Text(post.songInfo.album).font(.title)
Spacer()
Text(post.songInfo.artist)
}.padding()
Image(post.songInfo.albumArtUrl)
.resizable()
.aspectRatio(UIImage(named: "sweetner")!.size, contentMode: .fit)
HStack {
Image("plus-icon")
Spacer()
Image("comment-icon")
Spacer()
Image("headset-icon")
}.padding()
HStack {
Text(post.user.userName)
Spacer()
Text(post.textContent)
}.padding()
}
}
}
PostsView
import SwiftUI
struct PostsView: View {
@ObservedObject var fbVM = FirebaseInfo()
var body: some View {
List(fbVM.visiblePosts) { post in
PostView(post: post)
}
}
}
struct PostsView_Previews: PreviewProvider {
static var previews: some View {
PostsView()
}
}