2016-07-24 99 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