Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change ListStyle in List

Tags:

ios

swift

swiftui

In SwiftUI List Appears to have a property called ListStyle.

How can i change the style of the list

struct ListView : View { var body: some View {     NavigationView {     List(Item.create().identified(by: \.id)){ row in         NavigationButton(destination: DetailsView(item: row)) {             RowView(item: row)         }     }     .listStyle(StaticMember<PlainListStyle.Member>.self) // error here     .foregroundColor(.red)     .navigationBarTitle(Text("List View"))     .statusBar(hidden: false)     }   } } 

The conforming parties of ListStyle protocol are

  1. CarouselListStyle
  2. DefaultListStyle
  3. GroupedListStyle
  4. PlainListStyle
  5. SidebarListStyle

However i am struggling trying to set a new style for the list using it like this

.listStyle(StaticMember<PlainListStyle.Member>.self) 

I have tried so many ways, but each style confirming to the ListStyle is struct, like they're not enumerated values

Anyone have an idea how to change the style of List ?

Error in Xcode

Cannot convert value of type 'StaticMember.Type' (aka 'StaticMember>.Type') to expected argument type 'StaticMember<_>'

Using : .listStyle(StaticMember<PlainListStyle.Member>)

Error in Xcode

Cannot convert value of type '(StaticMember).Type' (aka 'StaticMember>.Type') to expected argument type 'StaticMember<_>'

Using : .listStyle(StaticMember<PlainListStyle()>) or .listStyle(StaticMember<PlainListStyle.self>)

Error in Xcode

'>' is not a postfix unary operator

like image 252
Mohmmad S Avatar asked Jun 06 '19 08:06

Mohmmad S


People also ask

Can we change bullets of an HTML list?

The default bullets can be replaced with other native options or completely removed using CSS to manipulate the list-style-type property. You can even change the UL bullet to a custom image or icon.


1 Answers

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
like image 59
CodeBender Avatar answered Sep 29 '22 19:09

CodeBender