【发布时间】:2023-03-16 02:12:01
【问题描述】:
我想在带有 4 个部分的 tableviewcell 上添加阴影(1 个 tableView 和 4 个 tableViewCell),最后一个单元格我想在 3 个侧面(左、右、下)添加阴影,但在除最后一个单元格之外的另一个单元格中我只想在 2 侧(左,右)添加阴影。我用单例和扩展 UIView 编写此代码。 这是最后一个单元格:
func dropShadowAtBottom() {
self.layer.masksToBounds = false
self.layer.shadowColor = UIColor.black.cgColor
self.layer.shadowOpacity = 0.2
self.layer.opacity = 0.3
self.layer.shadowOffset = CGSize(width: 0, height: 2)
self.layer.shadowRadius = 2
self.clipsToBounds = false
}
这对于除最后一个单元格之外的另一个单元格:
func dropShadowAtLeftAndRight() {
self.layer.masksToBounds = false
self.layer.shadowColor = UIColor.black.cgColor
self.layer.shadowOpacity = 0.5
self.layer.shadowOffset = CGSize(width: 0, height: 0)
self.layer.shadowRadius = 2
let shadowRect: CGRect = self.layer.bounds.insetBy(dx: 0, dy: 4); // inset top/bottom
self.layer.shadowPath = UIBezierPath(rect: shadowRect).cgPath
self.layer.rasterizationScale = UIScreen.main.scale
self.layer.shouldRasterize = true
}
我在 cellForRow 中调用这段代码:
if(indexPath.row == currentOrderHistory.listOrderItems.count - 1){
cell.bodyView.dropShadowAtBottomOnly()
}else{
cell.bodyView.dropShadowAtLeftAndRight()
}
return cell
现在这段代码可以工作了,但仍然不完美。单元格之间有空白。
我只是想让它们连接起来。
【问题讨论】:
-
如果您发布您想要实现的目标的图片,这将非常有帮助
-
尝试分享你想要达到的目标
-
我已经添加了图片。请点击“图片”文字
标签: ios swift uitableview swift3