UICollectionView 单元格绘制问题 swift
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
我希望获得这种类型的视图:
但是有些单元格是这样的:
而且我必须重新加载数据才能获取当前单元格视图。
仍然不明白为什么我会得到这个错误
您看到 "diamond like" 形状的图像的原因是因为 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
希望这对您有所帮助:)
在我的项目中,我有 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
我希望获得这种类型的视图:
但是有些单元格是这样的:
而且我必须重新加载数据才能获取当前单元格视图。 仍然不明白为什么我会得到这个错误
您看到 "diamond like" 形状的图像的原因是因为 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
希望这对您有所帮助:)