2016-12-05 26 views
0

我有表格視圖,我有一個自定義單元格。單元格中有一個標籤,它將在運行時有一個圓圈。現在,我寫了一些代碼,使其成爲圓形,但它不顯示圓形時表格視圖首先加載。當我滾動tableview時,它顯示UILabel周圍的圓圈。爲什麼滾動tableview後,UILabel的邊框會被設置?

我正在使用下面的代碼。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

    let cellId="NotificationCell" 
    let cell:NotificationCell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! NotificationCell 

    cell.label_taskCount.layer.cornerRadius = cell.label_taskCount.frame.size.height/2 
    cell.label_taskCount.layer.borderWidth = 1 
    cell.label_taskCount.layer.borderColor = UIColor.white.cgColor 
    cell.label_taskCount.layoutIfNeeded() 
    cell.label_taskCount.text = String(indexPath.row) 

    return cell 
    } 

回答

0

嘗試設置圓角半徑在NotificationCelllayoutSubViews

override func layoutSubviews() { 
    super.layoutSubviews() 
    self.label_taskCount.layer.cornerRadius = self.label_taskCount.frame.size.height/2 
    self.label_taskCount.layer.borderWidth = 1 
    self.label_taskCount.layer.borderColor = UIColor.white.cgColor 
} 
+0

它tableview.I的細胞都在的cellForRowAtIndexPath – dhiraj

+0

寫代碼,做它在定製Cell類。 – Venkat

+0

好吧,我試着讓我檢查 – dhiraj

相關問題