我试图List
通过每个单元格上的图像来获得手表上的正常值listRowBackground
。
但是,当我将图像设置为listRowBackground
标准的角半径时List
,就会消失(见下文)。
我尝试background
在单元格View
本身中设置修改,但这会导致同样的问题。查看可视化视图调试器,背景图像似乎远远超出了单元格本身。
struct ListView: View {
@ObservedObject var model: ListModel
var body: some View {
List {
ForEach(self.model.items) { item in
NavigationLink(destination: PlayerView(item: item)) {
ListCell(item: item).frame(height: 100)
}
.listRowBackground(Image(uiImage: item.image)
.resizable()
.scaledToFill()
.opacity(0.7)
)
}
}
.listStyle(CarouselListStyle())
.navigationBarTitle(Text("Today"))
}
}
@available(watchOSApplicationExtension 6.0, *)
struct ListCell: View {
var item: ListItem
var body: some View {
VStack(alignment: .leading) {
Text("\(self.item.length) MIN . \(self.item.category)")
.font(.system(.caption, design: .default))
.foregroundColor(.green)
.padding(.horizontal)
.padding(.top, 2)
Text(self.item.title)
.font(.headline)
.lineLimit(2)
.padding(.horizontal)
}
}
}
Run Code Online (Sandbox Code Playgroud)
图片: 带背景图片:
图片: 无背景图片:
Dim*_*ski 16
这适用于我Xcode 11.5,只需添加.clipped()
和 .cornerRadius(10)
修饰符。
List {
Text("Sample cell text")
.listRowBackground(
Color(.blue)
.clipped()
.cornerRadius(10))
}
Run Code Online (Sandbox Code Playgroud)
我想到了!
我将图像包裹在 a 内GeometryReader
并将clipped()
和添加cornerRadius(10)
到GeometryReader
.
并添加buttonStyle(PlainButtonStyle())
到NavigationLink
.
private func backgroundImage() -> some View {
return GeometryReader { g in
Image(<image>)
.resizable()
.blur(radius: 2)
.scaledToFill()
.frame(width: g.size.width, height: g.size.height)
}
.clipped()
.cornerRadius(10)
}
Run Code Online (Sandbox Code Playgroud)
然后添加.listRowBackground(self.backgroundImage())
到NavigationLink
.
归档时间: |
|
查看次数: |
4389 次 |
最近记录: |