【发布时间】:2020-05-18 10:04:23
【问题描述】:
我添加了视图作为表格视图单元格的背景,并且我为视图提供了阴影。在这里,当我运行 tableview 时,阴影不会正常出现,一旦我向下和向上滚动,阴影就会正常出现。
我根据这个答案给了阴影answer
代码:
extension UIView {
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
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! PlansTableViewCell
cell.containerView.dropShadow()
return cell
}
在像这样滚动阴影之前:
滚动后如下图:
运行后(滚动前)我还需要第二种图像输出,这里帮我写代码。
【问题讨论】:
标签: swift uitableview uiview shadow