SWIFTUI: Take out a gray rectangle on top of the TabBar

纵饮孤独 提交于 2021-01-28 20:43:09

问题


I have a problem related on my List view. The question is simple: how can I get rid of that wierd gray rectangle showing on top of the TabBar? I didn't code that, I just implemented a controller with a List and NavigationBar and then it showed that thing.

For more clear explanation I post the images:

ItemRow.swift code:

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

}

thanks a lot for the help


回答1:


Remove the marked part of hack from TabBar view and that glitch will go.

Tested with Xcode 11.4 / iOS 13.4

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


来源:https://stackoverflow.com/questions/62279724/swiftui-take-out-a-gray-rectangle-on-top-of-the-tabbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!