我正在尝试用新的 iOS 14 UIListContentConfiguration 和 UIBackgroundConfiguration 替换我的 UITableViewCell 配置,但我不知道如何执行最基本的自定义。
例如,我有一个测试单元格,在我的数据源cellForRowAt:
中,我正在像这样配置背景:
let v = UIImageView(image: UIImage(named:"linen.png"))
v.contentMode = .scaleToFill
cell.backgroundView = v
let v2 = UIView()
v2.backgroundColor = UIColor.blue.withAlphaComponent(0.2)
cell.selectedBackgroundView = v2
这个想法是我们有一个图像作为单元格的背景,当用户点击单元格以选择它时,我们用透明的蓝色色调覆盖它。选择单元格时,它selectedBackgroundView
位于前面。backgroundView
好的,那么我该如何使用 UIBackgroundConfiguration 呢?我看到如何配置背景视图:
var back = UIBackgroundConfiguration.listPlainCell()
let v = UIImageView(image: UIImage(named:"linen.png"))
v.contentMode = .scaleToFill
back.customView = v
cell.backgroundConfiguration = back
但是当有选择时会发生什么呢?没有selectedCustomView
,而且我在这里看不到针对不同州的不同背景的任何规定。