I want to add spacing between multiple custom cells. I have multiple sections that contains the cells.
I have a ViewController class for the UITableView where I specify the information:
struct customCell {
let title: String
}
func configure() {
models.append(Section(title: "", options: [
customCell(title: "Sounds"){
},
}
And I have a different UITableViewCell class where I use the layoutSubViews() method:
override func layoutSubviews() {
super.layoutSubviews()
contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top: 0, left: 0, bottom: 10, right: 0))
I see other solutions on this website, where they get the spacing by using UIEdgeInsets.
I tried using the layoutSubViews() method but that didn’t work, it pushes the content of the cell upwards instead of adding spaces between cells:
When I use all insets:
contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top:15, left: 15, bottom: 15, right: 15))
The content gets pushed inwards from all sides:
What am I doing wrong?
2
Answers
Try this:
And the other solution can be that if you use UIView in your contentView and declare other objects in that View, it will behave like you add space between cell.
Try to set nagative value for inset, like this: