如何在表视图中区分两个表视图单元格之间的间隙?

时间:2018-11-25 09:49:55

标签: ios swift

我已经尝试过此代码,但对我而言不起作用:

let whiteBackgroundLayerView: UIView = UIView(frame: CGRect(x: 10 , y: 8, width: self.view.frame.size.width - 20, height: 90))
whiteBackgroundLayerView.layer.backgroundColor = CGColor(colorSpace: CGColorSpaceCreateDeviceRGB(), components: [1.0, 1.0, 1.0, 0.8])
whiteBackgroundLayerView.layer.masksToBounds = false
whiteBackgroundLayerView.layer.cornerRadius = 2.0
cell.contentView.addSubview(whiteBackgroundLayerView)
cell.contentView.sendSubviewToBack(whiteBackgroundLayerView)

我希望输出如下:

enter image description here

1 个答案:

答案 0 :(得分:0)

在您的自定义单元格中,添加以下代码:

override func layoutSubviews() {
    super.layoutSubviews()
    contentView.frame = UIEdgeInsetsInsetRect(contentView.frame, UIEdgeInsetsMake(10, 10, 10, 10))
}