如何在列表中更改ListStyle [英] How to change ListStyle in List

查看:74
本文介绍了如何在列表中更改ListStyle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SwiftUI中List似乎具有一个名为ListStyle的属性.

In SwiftUI List Appears to have a property called ListStyle.

如何更改列表的样式

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)
    }
  }
}

ListStyle协议的符合方是

  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)

我尝试了很多方法,但是确认ListStyle的每种样式都是struct,就像它们不是枚举值一样

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

任何人都有一个想法如何更改List的样式?

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

Xcode错误

无法将类型"StaticMember.Type"(也称为"StaticMember> .Type")的值转换为预期的参数类型"StaticMember< __>"

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

使用:.listStyle(StaticMember<PlainListStyle.Member>)

Xcode错误

无法将类型'(StaticMember).Type'(又名'StaticMember> .Type')的值转换为预期的参数类型'StaticMember< __>'

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

使用:.listStyle(StaticMember<PlainListStyle()>).listStyle(StaticMember<PlainListStyle.self>)

Xcode错误

'>'不是后缀一元运算符

'>' is not a postfix unary operator

推荐答案

从Xcode 11 beta 5开始,Apple要求以下内容,简要概述了

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

.listStyle(GroupedListStyle())

以下值可用于iOS 13和watchOS 6.0:

  • PlainListStyle

DefaultListStyle

请注意,Apple在iOS 13测试版期间更改了样式.所以不要 在iOS 14发行之前,请考虑这些官方规定.

Note that Apple changed styles during the iOS 13 beta. So do not consider these official until iOS 14 is released.

以下值可用于iOS 14 Beta:

  • InsetGroupedListStyle
  • InsetListStyle
  • SidebarListStyle
  • InsetGroupedListStyle
  • InsetListStyle
  • SidebarListStyle

此问题的某些答案还包括特定于watchOS的样式,尽管该问题被标记为iOS,但并未明确标记.为了完整性...

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 6.0样式:

  • CarouselListStyle

watchOS 7.0样式:

  • EllipticalListStyle

这篇关于如何在列表中更改ListStyle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆