2016-07-24 101 views
1

我想在表格视图单元格周围添加边框。以下是cellForRowAtIndexPath代码:UITableViewCell右侧的边框不可见

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) 
     cell.separatorInset.left = 20.0 
     cell.separatorInset.right = 20.0 
     cell.separatorInset.top = 20.0 
     cell.separatorInset.bottom = 20.0 
     cell.layer.borderWidth = 3 
     cell.layer.cornerRadius = 20.0 
     cell.layer.borderColor = UIColor.colorWithHexString("80CBC4").CGColor 
     return cell 
    } 

边界正在为三个方面,除了右侧: enter image description here

enter image description here

+0

检查单元格宽度。 –

+0

已经为单元格视图定义了“宽度”和“高度”约束 – triandicAnt

+0

从我最近的回答中尝试解决方案... –

回答

0

maskToBounds设置为true层的财产试试你的代码:

当这个属性的值是true,Core动画创建一个与图层边界相匹配的隐式剪贴蒙版,并包含任何角落半径效果。如果还指定了掩码属性的值,则将两个掩码相乘以获取最终掩码值。 此属性的默认值为false

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) 
     cell.separatorInset.left = 20.0 
     cell.separatorInset.right = 20.0 
     cell.separatorInset.top = 20.0 
     cell.separatorInset.bottom = 20.0 
     cell.contentView.layer.borderWidth = 3 
     cell.contentView.layer.cornerRadius = 20.0 
     cell.contentView.layer.borderColor = UIColor.colorWithHexString("80CBC4").CGColor 
     cell.contentView.layer.masksToBounds = true 
     return cell 
} 
+0

它不工作与'masksToBounds' – triandicAnt

+0

好吧,而不是'cell.layer'尝试'cell.contentView.layer',现在将添加代码.. –

+0

仍然有相同的结果 – triandicAnt

0

您可能已经指定了固定宽度的限制。 您应该删除它并指定前导和尾随约束。

+0

问题是我缺少'tableView'的约束而不是'cellView' – triandicAnt