I need to add padding so space between each cell in each section in swift 2.1
but all I managed to do was adding header for section which I don't want that.
how can I add space between dynamic table cells?
Here is the code for adding header:
// Set the spacing between sections
override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 10
}
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = UIView()
header.backgroundColor = UIColor.clearColor()
return header
}
Here is creating table view code:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.tableData.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//Table view cells are reused and should be dequeued using a cell identifier.
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
let rowData = self.tableData[indexPath.row]
cell.textLabel!.text = rowData.name
cell.textLabel!.textAlignment = .Right
if let url = NSURL(string: rowData.img),
data = NSData(contentsOfURL: url)
{
cell.imageView?.image = UIImage(data: data)
}
return cell
}
Right now my table view look like this:
update code and table view :
There is no spacing between cells in a table view. Only in a collection view.
The options available to you are...
Use a collection view instead. It's relatively easy to make it look like a table view. Using this you can use the inter item spacing.
Increase the height of the cells by 2 pixels and add a blank area to the top or bottom of each. This will give the illusion of adding space between them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With