【问题标题】:SWIFTUI: Take out a gray rectangle on top of the TabBarSWIFTUI:在 TabBar 顶部取出一个灰色矩形
【发布时间】: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)
        }

}

非常感谢您的帮助

【问题讨论】:

标签: xcode swiftui tabbar


【解决方案1】:

TabBar 视图中删除标记的 hack 部分,该故障就会消失。

使用 Xcode 11.4 / iOS 13.4 测试

        }   .onAppear {
//            UITabBar.appearance().isTranslucent = false     // << this one !!
            UITabBar.appearance().barTintColor = UIColor(named: "IkeaBlu")
        }.accentColor(Color(.white))

【讨论】:

  • 它起作用了...非常感谢,伙计...我可以问为什么通过取出那部分它删除了矩形?再次感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-09-14
  • 2017-10-13
  • 1970-01-01
  • 2020-11-10
  • 1970-01-01
  • 2023-03-05
  • 1970-01-01
相关资源
最近更新 更多