How to change ListStyle in List

后端 未结 3 990
你的背包
你的背包 2021-02-05 06:42

In SwiftUI List Appears to have a property called ListStyle.

How can i change the style of the list

struct ListView : View {         


        
相关标签:
3条回答
  • 2021-02-05 06:57

    Update for Xcode Beta 5 and nexts

    After Xcode Beta 5 this approach is now deprecated; 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 }
    }
    
    0 讨论(0)
  • 2021-02-05 06:57

    in Xcode 11.2.1, Right answer is in the below.

    .listStyle(GroupedListStyle())
    
    Conforming Types  ->
    CarouselListStyle
    DefaultListStyle
    GroupedListStyle
    PlainListStyle
    SidebarListStyle
    

    ref:https://developer.apple.com/documentation/swiftui/liststyle

    0 讨论(0)
  • 2021-02-05 06:58

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

    .listStyle(GroupedListStyle())
    

    The following is 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
    0 讨论(0)
提交回复
热议问题