SwiftUI 禁用列表边框 iOS 14 [英] SwiftUI disable list border iOS 14

查看:41
本文介绍了SwiftUI 禁用列表边框 iOS 14的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现如果视图包含导航视图,SwiftUI iOS 14 中的列表会有类似边框的东西.有没有办法禁用边框?因为边框破坏了我的应用程序的设计.

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.

这是代码中不包含 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]
            VStack{
                List(restaurants) { restaurant in
                    Text(restaurant.name)
                }
            }
        }
    }
}

这是包含NavigationView的代码

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

            }
        }
    }
}

我想要的设计是第一张照片.我不知道如何禁用添加到列表 iOS14 中的边框.有什么建议吗?

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?

推荐答案

尝试显式使用纯列表样式(我假设现在他们默认使用插入列表样式)

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

这篇关于SwiftUI 禁用列表边框 iOS 14的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆