[英]UICollectionView cell drawing issues swift
在我的项目中,我有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
我希望得到这种看法:
但是某些单元格显示如下:
我必须reloatData来获取当前的单元格视图。 仍然不明白为什么我得到这个错误
之所以看到形状像“菱形”的图像,是因为cornerRadius
目前设置为动态int,并且设置为一半以上。 您应该使用的cornerRadius应该比(cell.bounds.size.height-10)/2
少得多。
正如迈克尔所说,请尝试使用类似以下内容的方法:
cell.personImage.layer.cornerRadius = testView.frame.width / 2
看看你的结果是什么。
您可以尝试使用以下代码设置动态拐角半径:
cell.personImage.layer.cornerRadius = cell.personImage.frame.width / 2.0
希望这可以帮助 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.