自定义UITableViewCell - 在每个单元格之间添加边距

时间:2013-10-28 16:25:04

标签: objective-c xcode

是否可以在UITableView单元格之间应用边距?

简介要求表格单元格如下所示 -

enter image description here

我有一个自定义单元格类来设置背景/字体/单独标签的样式 - 但无法弄清楚如何应用任何类型的间距!

3 个答案:

答案 0 :(得分:9)

我将通过以下方式执行此操作:首先,确保background及其UITableViewCell的{​​{1}}颜色为contentView,然后添加略小于[UIColor clearColor]的子视图您的单元格contentView(以便height = CGRectGetHeight(contentView) - margin)并用您需要的颜色填充它。然后为backgroundView设置UITableView,这应该可以解决问题。

答案 1 :(得分:2)

使用Swift语言在TableView中获取两个单元格之间空间的最佳方法。

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

    cell.contentView.backgroundColor=UIColor.clearColor()

    var whiteRoundedCornerView:UIView!
    whiteRoundedCornerView=UIView(frame: CGRectMake(5,10,self.view.bounds.width-10,120))
    whiteRoundedCornerView.backgroundColor=UIColor(red: 174/255.0, green: 174/255.0, blue: 174/255.0, alpha: 1.0)
    whiteRoundedCornerView.layer.masksToBounds=false
    whiteRoundedCornerView.layer.shadowOpacity = 1.55
    whiteRoundedCornerView.layer.shadowOffset = CGSizeMake(1, 0);
    whiteRoundedCornerView.layer.shadowColor=UIColor(red: 53/255.0, green: 143/255.0, blue: 185/255.0, alpha: 1.0).CGColor
    whiteRoundedCornerView.layer.cornerRadius=3.0
    whiteRoundedCornerView.layer.shadowOffset=CGSizeMake(-1, -1)
    whiteRoundedCornerView.layer.shadowOpacity=0.5
    cell.contentView.addSubview(whiteRoundedCornerView)
    cell.contentView.sendSubviewToBack(whiteRoundedCornerView)
}

答案 2 :(得分:-4)

底部细胞marigin

tableView.contentInset = UIEdgeInsetsMake(0, 0, 20, 0);