Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Spacing Between Basic Table View Cells

I have basic table view cells that I want to set some spacing between them.

enter image description here

I tried

cell.contentView.layoutMargins.top = 8

and

cell.layoutMargins.top = 8 

but that didn't work. I know I can create a custom cell, but I want to know how I can add margins this way.

EDIT:

Then I changed the cell style to custom:

enter image description here

and added a view so I can set up some constraints to it

enter image description here

but the results still the same, no spacing between cells, and it kinda ignored the custom view, i guess because it needs a custom class for the cell, but I don't want to do that.

enter image description here

like image 554
fullmoon Avatar asked Apr 25 '26 13:04

fullmoon


1 Answers

You should not add spacing between cells themselves, but rather add a custom containerView to cell's contentView with a top and/or bottom constraints.

enter image description here

like image 146
alexburtnik Avatar answered Apr 27 '26 01:04

alexburtnik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!