我有一个
SwiftUI
List
,每行下面都有阴影,以添加3D外观。
行看起来很棒,但截面标题文本似乎从列表中继承了阴影,而我尝试过的任何内容都无法删除它。
基于以下代码的效果的screenshot:
添加列表格式为a
.compositeGroup()
这没有效果
.textCase()
创建自定义
.none
将阴影添加到行视图本身
View
compositeGroup
HStack
Text
.listStyle
文本不继承
PlainListStyle
视图上的阴影格式?最小可再现的示例:
DefaultListStyle
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
。