[问题描述]
在练习SwiftUI时,尝试实现Reminder中「我的列表」的样式:
但是在尝试的过程中使用了如下的代码:
struct ListView: View {
var body: some View {
VStack {
List {
Text("Item 1")
Text("Item 2")
Text("Item 3")
Text("Item 4")
Text("Item 5")
Text("Item 6")
}
.cornerRadius(10)
}
.navigationTitle("List")
.embedInNavigationView()
}
}
看到的页面是
预估计是影响了AutoLayout相关的布局。
【解决方案】
struct ListView: View {
var body: some View {
VStack {
List {
Text("Item 1")
Text("Item 2")
Text("Item 3")
Text("Item 4")
Text("Item 5")
Text("Item 6")
}
.listStyle(InsetGroupedListStyle())
}
.navigationTitle("List")
.embedInNavigationView()
}
}
变更点是使用了InsetGroupedListStyle(),能解决Navigation中的List的圆角展示问题。
【其他】
embedInNavigationView():
extension View{
func embedInNavigationView() -> some View {
NavigationView{
self
}
}
}