【发布时间】:2020-09-28 11:03:20
【问题描述】:
我的列表视图有问题。问题很简单:我怎样才能摆脱显示在 TabBar 顶部的那个奇怪的灰色矩形?我没有编写代码,我只是用 List 和 NavigationBar 实现了一个控制器,然后它显示了那个东西。
为了更清楚的解释,我发布了图片:
ItemRow.swift 代码:
import SwiftUI
struct ItemRow: View {
static let colors: [String: Color] = ["D": .purple, "G": .orange, "N": .red, "S": .yellow, "V": .pink]
var item: MenuItem
var body: some View {
NavigationLink(destination: Text(item.name)) {
HStack {
Image(item.thumbnailImage)
.clipShape(Circle())
.overlay(Circle().stroke(Color("IkeaBlu"), lineWidth: 2))
VStack(alignment: .leading){
Text(item.name)
.font(.headline)
Text("€ \(item.price)")
}.layoutPriority(1)
Spacer()
ForEach(item.restrictions, id: \.self) { restriction in
Text(restriction)
.font(.caption)
.fontWeight(.black)
.padding(5)
.background(Self.colors[restriction, default: .black])
.clipShape(Circle())
.foregroundColor(.white)
}
}
}
}
}
struct ItemRow_Previews: PreviewProvider {
static var previews: some View {
ItemRow(item: MenuItem.example)
}
}
非常感谢您的帮助
【问题讨论】:
-
ItemRow 在这里无关紧要。你会提供复制代码吗? How to create a Minimal, Reproducible Example
-
@Romesh Singhabahu 请帮助 MenuItem.example 示例是什么
-
@TanjimaKothiya 抱歉,我打错字了,只是说这是文件名
-
@Asperi 这是我公开的 github 存储库的链接:github.com/Rosin355/IKEAFood/settings