SWIFTUI。在TabBar的上方拿出一个灰色的矩形

问题描述 投票:0回答:1

我的列表视图有一个问题。问题很简单:我如何才能摆脱TabBar顶部显示的那个奇怪的灰色矩形?我没有写代码,我只是实现了一个控制器,有一个列表和导航条,然后它就显示了那个东西。

为了更清楚的解释,我把图片贴出来。

enter image description here

enter image description here

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)
        }

}

非常感谢你的帮助

xcode swiftui tabbar
1个回答
0
投票

移除黑客的标记部分 TabBar 视图,这个小毛病就会消失。

用Xcode 11.4 iOS 13.4进行测试

demo

        }   .onAppear {
//            UITabBar.appearance().isTranslucent = false     // << this one !!
            UITabBar.appearance().barTintColor = UIColor(named: "IkeaBlu")
        }.accentColor(Color(.white))
© www.soinside.com 2019 - 2024. All rights reserved.