Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add space between tableView cell?

I'm trying to add space between a UITableViewCell. Where do i need to provide anchoring for space?

enter image description here

like image 575
Kabindra Karki Avatar asked Feb 21 '26 04:02

Kabindra Karki


1 Answers

You can use one of these ways:

First way: Change frame of the contentView of your TableViewCell. Override layoutSubviews method in your TableViewCell like this:

 override func layoutSubviews() {
      super.layoutSubviews()
      let bottomSpace: CGFloat = 10.0 // Let's assume the space you want is 10
      self.contentView.frame = self.contentView.frame.inset(by: UIEdgeInsets(top: 0, left: 0, bottom: bottomSpace, right: 0))
 }

Second way: Change your UITableView Datasource and Delegate: number of sections in your tableview will be the same as your items count, with one item in each section. And there is one footer view for each section (with height is equal to the space you want to), dont forget to set background color of the footer view if needed.

like image 172
jacob Avatar answered Feb 23 '26 03:02

jacob



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!