我想添加阴影在tableviewcell与4节(1 tableView与4 tableViewCell),最后一个单元格我想添加三边(左,右,底部)阴影,但在另一个单元格,但最后一个单元格,我只是想在左侧(左侧,右侧)添加阴影。我用singleton和扩展UIView编写这段代码。 此为最后一个单元格:如何在tableviewcell swift 3添加阴影?
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
现在这个代码的工作,但仍不完美。细胞之间有白色空间。
我只想让他们连接。
如果您发布想要实现的图像 –
试图分享您想要实现的内容 –
我会添加图片。请klik的“图片”文字 –