TableView的单元格中有阴影

时间:2020-05-09 01:36:47

标签: ios swift tableview

嗨,我有正常的TableView,并且我想从每侧(上,下,左,右)将其更新为TableView中每个单元格之间的空格/空白

您可以在此处看到: enter image description here

1 个答案:

答案 0 :(得分:4)

首先,您需要创建一个新的UITableViewCell,该UITableViewCell中具有一个viewView contentView。您需要使添加的视图小于视图并填充该视图,以便可以在每个tableviewCell之间创建间隙。

喜欢:

enter image description here

与创建约束相比,约束将使视图变小并适合像这样的单元格:

enter image description here

之后,您可以在此处使用此扩展在视图中创建阴影:

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()

结果将如下所示:

enter image description here