How to change ListStyle in List

后端 未结 3 989
你的背包
你的背包 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 }
    }
    

提交回复
热议问题