Kabindra Karki
Kabindra Karki

Reputation: 31

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

Upvotes: 2

Views: 10217

Answers (1)

jacob
jacob

Reputation: 1052

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.

Upvotes: 8

Related Questions