答案 0 :(得分:4)
首先,您需要创建一个新的UITableViewCell,该UITableViewCell中具有一个viewView contentView。您需要使添加的视图小于视图并填充该视图,以便可以在每个tableviewCell之间创建间隙。
喜欢:
与创建约束相比,约束将使视图变小并适合像这样的单元格:
之后,您可以在此处使用此扩展在视图中创建阴影:
https://stackoverflow.com/a/40720122/8792385
代码段是这样的:
extension UIView {
// OUTPUT 1
func dropShadow(scale: Bool = true) {
layer.masksToBounds = false
layer.shadowColor = UIColor.black.cgColor
layer.shadowOpacity = 0.5
layer.shadowOffset = CGSize(width: -1, height: 1)
layer.shadowRadius = 1
layer.shadowPath = UIBezierPath(rect: bounds).cgPath
layer.shouldRasterize = true
layer.rasterizationScale = scale ? UIScreen.main.scale : 1
}
}
然后,您只需要为视图创建引用,并在配置单元格方法中调用
view.dropShadow()
结果将如下所示: