spacing between UITableViewCells swift3

Ankit Kumawat picture Ankit Kumawat · Dec 4, 2017 · Viewed 21.3k times · Source

I am creating a IOS app in swift and want to add spacing between cells like this

enter image description here

I would like to give space of each table view cell same like my attach image. How I can do that? and Right now all cells are coming without any space. swift3

Answer

user8336100 picture user8336100 · Dec 4, 2017

you can try this in your class of tableView cell:

class cell: UITableViewCell{
override var frame: CGRect {
    get {
        return super.frame
    }
    set (newFrame) {
        var frame =  newFrame
        frame.origin.y += 4
        frame.size.height -= 2 * 5
        super.frame = frame
    }
  }
}