swiftui:如何防止截面标题继承列表视图的阴影?

问题描述 投票:0回答:1

我有一个

SwiftUI
List
,每行下面都有阴影,以添加3D外观。

行看起来很棒,但截面标题文本似乎从列表中继承了阴影,而我尝试过的任何内容都无法删除它。 基于以下代码的效果的screenshot:

Screenshot of the shadow effect到目前为止,我尝试了什么:

添加列表格式为a

.compositeGroup()
    ,然后应用阴影
  • 这没有效果
    • semthing sectrable to sectionheader to
    • .textCase()
  • this删除了所有文本格式,但不是文本中的阴影...
  • 
    
    创建自定义
    .none
      为截面的标题以其自己的格式
    • 这种观点仍然继承了阴影
  • 将阴影添加到行视图本身
    
      这在行中给出了所有文本,而不是“行”视图
    • 在视图上申请时,这也继续是正确的
    影子确实从本文中消失了
    • 将行中的阴影添加到the the lo
    • 上述效果
    • 将整个部分整合在一起,然后进行
    • View
    • 视图
    这种观点仍然继承了阴影
  • 设置
      compositeGroup
    • to to
    • HStack
  • Text
  • 没有效果,更改了行宽度
    我完全亏损了。
  • 我如何使
  • .listStyle
    文本不继承
    PlainListStyle
    视图上的阴影格式?
    
    最小可再现的示例:
    DefaultListStyle
        
    	
    • 如果将the应用于整体上,则将其应用于列表中的所有内容。这包括“截面”标题。
    • 一个解决方法是将阴影效果应用于列表行。这在
    如何在列表上使用双阴影的答案中证明了这一点?(这是我的答案)。但是,这项技术有点麻烦。
  • 更简单的解决方法是隐藏本机部分标题,并在同一空间中显示自己的标头:

Section

可用于与位置完全匹配。我发现如果使用
List
,它最有用。
在线,可以用

struct MinReproduceExample: View { var body: some View { List { Section(header: MinReproCell(text: "Section Title")) { MinReproCell(text: "Cell text") //causes shadow on cell text //does not create red shadow on cell view itself .shadow(color:.red, radius: 5, x:-3, y:3) } } .background(.clear) //Must be here to make cell view shadow red. //Also causes Section title to be red //does not cause cell text to have red shadow .shadow(color:.red, radius: 5, x:-3, y:3) //scrollContent required to be clear to show shadows of views .scrollContentBackground(.hidden) } } struct MinReproCell: View { var text: String var body: some View { Text(text).foregroundStyle(.black) } } struct MinReproSection:View { var text: String var body: some View { Text(text) .foregroundStyle(.black) .font(Font.system(size: 20, weight: .bold)) .textCase(.none) // has no effect on section text shadow } }

和填充来调整其位置。

模仿样式,将字体设置为
.shadow
swift list inheritance swiftui shadow
1个回答
0
投票

List


    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.