2016-12-05 89 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

相关问题