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

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

问题描述

我发现,如果视图包含navigationView,则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天全站免登陆