ios - UICollectionView 单元格绘图问题 swift

标签 ios swift2 swift2.1

在我的项目中,我有 uicolelctionview和自定义单元格。在 collectionView:CellForItemAtIndexPath我得到了自定义单元格

let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! CustomCollectionCell

并添加此代码
cell.personImage.layer.cornerRadius=(cell.bounds.size.height-10)/2
cell.personImage.layer.borderWidth=3
cell.personImage.layer.masksToBounds=true

我希望得到这种类型的 View :

enter image description here

但一些细胞看起来像这样:

enter image description here

我必须 reloatData 才能获得当前的单元格 View 。
仍然无法理解为什么我会得到这个错误

最佳答案

您可以尝试使用以下代码设置动态角半径:

cell.personImage.layer.cornerRadius = cell.personImage.frame.width / 2.0

希望这可以帮助 :)

关于ios - UICollectionView 单元格绘图问题 swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33180379/

相关文章:

swift - 定义在闭包中使用的泛型类型

ios - UIWebView 不会在 Swift 中重新加载新的 URL

ios - iPad 专业版。禁用原生 2732×2048 分辨率

ios - libiPhone-lib.a 在 Unity 构建到 xcode 后太大(大小约为 1.1G!)

ios - 如何在 swift 2.3 中设置字符串格式

arrays - 我可以创建一个从 Array 派生的类吗?

ios - 单行 UILabel 拥抱不适用于自动收缩

iphone - 为什么我会看到有关 NSAutoreleasePool 不可用的警告消息?

macos - 如何使用XPath和Swift 2.0解析html?