我已经尝试过此代码,但对我而言不起作用:
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)
我希望输出如下:
答案 0 :(得分:0)
在您的自定义单元格中,添加以下代码:
override func layoutSubviews() {
super.layoutSubviews()
contentView.frame = UIEdgeInsetsInsetRect(contentView.frame, UIEdgeInsetsMake(10, 10, 10, 10))
}