SwiftUI disable list border iOS 14 [duplicate]

匆匆过客 提交于 2020-12-26 08:20:03

问题


I found the list in SwiftUI iOS 14 will have something like border if the view contained navigationView. Is there any solution to disable the border? Coz the border break the design of my application.

Here is the code that contained no NavigationView inside the code.

struct ContentView: View {
    @State var isPresent = false
    
    var body: some View {
        let first = Restaurant(name: "Joe's Original")
        let second = Restaurant(name: "The Real Joe's Original")
        let third = Restaurant(name: "Original Joe's")
        let restaurants = [first, second, third]
            VStack{
                List(restaurants) { restaurant in
                    Text(restaurant.name)
                }
            }
        }
    }
}

Here is the code that contained NavigationView

struct ContentView: View {
    @State var isPresent = false
    
    var body: some View {
        let first = Restaurant(name: "Joe's Original")
        let second = Restaurant(name: "The Real Joe's Original")
        let third = Restaurant(name: "Original Joe's")
        let restaurants = [first, second, third]
        NavigationView{
            VStack{
                List(restaurants) { restaurant in
                    Text(restaurant.name)
                }

            }
        }
    }
}

The design that I want is the first photo. I have no idea how to disable the border that added into the list iOS14. Any suggestion?


回答1:


Try to use plain list style explicitly (I assume now they used inset list style by default)

    NavigationView{
        VStack{
            List(restaurants) { restaurant in
                Text(restaurant.name)
            }
            .listStyle(PlainListStyle())     // << here !!
        }
    }


来源:https://stackoverflow.com/questions/63986335/swiftui-disable-list-border-ios-14

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