表格视图单元的填充

时间:2020-05-25 16:02:17

标签: ios swift uitableview cell padding

我将单元格添加到表中并使用xib进行了设置。现在它们是桌子的整个宽度。 How can I add indentation on the right and left for these cells?我尝试了以下代码,但没有帮助。

override func awakeFromNib() {
        super.awakeFromNib()
        contentView.frame = frame.inset(by: UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10))
    }

1 个答案:

答案 0 :(得分:1)

在单元格中创建一个子视图,将其约束赋予超级视图(即单元格),然后将现有子视图添加到此新添加的视图中。还有其他方法,这是我多年来发现的最简单的方法。