【发布时间】:2018-04-06 18:34:45
【问题描述】:
我正在尝试以这种方式将圆形图像附加到我的自定义表格单元格中:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let content : Content = contentsCollection.contents[indexPath.row]
let channel : Channel = contentsCollection.channel(withId: content.channel!.id)
let cell = tableView.dequeueReusableCell(withIdentifier: "ContentCell") as! ContentCell
cell.layoutSubviews()
let channelPicture = URL(string: channel.picture)
cell.channelImageView.kf.setImage(with: channelPicture)
//Rounded image
cell.channelImageView.layer.cornerRadius = cell.channelImageView.frame.height/2
return cell
}
问题是,第一次显示视图控制器时,图像视图仍然是方形。只有“隐藏”的单元格具有圆形图像视图。
似乎是这篇文章中记录的问题:https://medium.com/@adinugroho/circular-uiimageview-in-uitableview-cell-e1a7e1b6fe63
但我无法为我的实现找到解决方法。
【问题讨论】:
-
尝试在
willDisplay:forRowAt:委托方法中设置cornerRadius。 -
试试这个 cell.channelImageView.clipsToBounds = true
标签: swift uitableview uiimageview kingfisher