简体   繁体   中英

SwiftUI List with SidebarListStyle does not have Rounded Corners?

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

backup

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM