I am having an Issue
with Lists
in SwiftUI
.
Problem: Pretty simple, I am having a List
with .listStyle(SidebarListStyle())
inside a NavigationView
and the Corners are not Rounded (see Image below).
My Code:
NavigationView {
List {
Label("Option", systemImage: "list.bullet.rectangle")
Label("Option", systemImage: "tv")
Label("Option", systemImage: "mail.stack")
}
.listStyle(SidebarListStyle())
.navigationTitle("Options")
}
Outcome:
Question: How can I accomplish the Standard iOS 14 List Design
with Rounded Corners?
Thanks a lot for your help!
For that you need different style
List {
Label("Option", systemImage: "list.bullet.rectangle")
Label("Option", systemImage: "tv")
Label("Option", systemImage: "mail.stack")
}
.listStyle(InsetGroupedListStyle())
Update: using conditional list style
NavigationView {
List {
Label("Option", systemImage: "list.bullet.rectangle")
Label("Option", systemImage: "tv")
Label("Option", systemImage: "mail.stack")
}
.sidebarStyle(if: UIDevice.current.userInterfaceIdiom == .pad)
.navigationTitle("Options")
}
and helper extension
extension List {
@ViewBuilder
func sidebarStyle(if flag: Bool) -> some View {
if flag {
self.listStyle(SidebarListStyle())
} else {
self.listStyle(InsetGroupedListStyle())
}
}
}