Reputation: 8651
I am trying to give each cell spacing on each side by 5 and then make the corners rounded.
I have this so far:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 100.0;
}
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
cell.contentView.backgroundColor = UIColor.clearColor()
var whiteRoundedView : UIView = UIView(frame: CGRectMake(0, 10, self.view.frame.size.width, 70))
whiteRoundedView.layer.backgroundColor = CGColorCreate(CGColorSpaceCreateDeviceRGB(), [1.0, 1.0, 1.0, 1.0])
whiteRoundedView.layer.masksToBounds = false
whiteRoundedView.layer.cornerRadius = 3.0
whiteRoundedView.layer.shadowOffset = CGSizeMake(-1, 1)
whiteRoundedView.layer.shadowOpacity = 0.5
cell.contentView.addSubview(whiteRoundedView)
cell.contentView.sendSubviewToBack(whiteRoundedView)
}
This will make each cell have a width of 100% which I dont want to since I want space on the sides as well.
It also feels a bit laggy when scrolling through a long list.
So is there a better solution?
Upvotes: 0
Views: 574
Reputation: 535
A little trick: Customize your tableview cell, add a main view to your cell's contentview, you set margins and corner radius to this main view, say you want a spacing by 6 between two cells, then you set your main view 3 points margins to cell's contentview both top and bottom
Upvotes: 1