How to change ListStyle in List

Update for Xcode 13

So Apple added an extension to have a syntax similar to Xcode 11 Beta 5 and lower:

extension ListStyle where Self == GroupedListStyle {

    /// The list style that describes the behavior and appearance of a grouped
    /// list.
    ///
    /// On iOS, the grouped list style displays a larger header and footer than
    /// the ``ListStyle/plain`` style, which visually distances the members of
    /// different sections.
    public static var grouped: GroupedListStyle { get }
}

So again we can use this now:

.listStyle(.grouped)

Update for Xcode 11 Beta 5 till Xcode 12

After Xcode Beta 5 the listStyle(.grouped) approach is deprecated (until Xcode 12); now Apple created a struct implementation for every style. So you should do like: .listStyle(GroupedListStyle()). Same approach is applied to other styles available.

Old implementation for pre beta 5

Just do .listStyle(.grouped). For other list style use

  • .carousel
  • .default
  • .plain
  • .sidebar

Basically you are just passing ListStyle.grouped to the method, but thanks to swift type inference you don't need to specify the struct. Every static member work in this way.

StaticMember means that there is a static member in the ListStyle protocol. The declaration is this.

extension StaticMember where Base : ListStyle {

    /// A `ListStyle` that implements the system default grouped `List`
    /// interaction and appearance.
    public static var grouped: GroupedListStyle.Member { get }
}

As of Xcode 11 beta 5, Apple requires the following, as briefly outlined here:

.listStyle(GroupedListStyle())

The following is a breakdown on the various styles and where they can be used between iOS and watchOS, along with when they were introduced.

iOS and watchOS

Introduced with iOS 13 and watchOS 6:

  • PlainListStyle

  • ListStyle

  • DefaultListStyle

iOS Only

Introduced with iOS 13:

  • GroupedListStyle

Introduced with iOS 14:

  • InsetGroupedListStyle
  • InsetListStyle
  • SidebarListStyle

Some answers to this question also include styles that are watchOS specific, but are not clearly marked as such, despite the question being tagged iOS. For completeness...

watchOS Only

Introduced with watchOS 6:

  • CarouselListStyle

Introduced with watchOS 7:

  • EllipticalListStyle

Tags:

Ios

Swift

Swiftui