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
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
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.
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.
Introduced with iOS 13 and watchOS 6:
PlainListStyle
ListStyle
DefaultListStyle
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...
Introduced with watchOS 6:
CarouselListStyle
Introduced with watchOS 7:
EllipticalListStyle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With