【发布时间】:2015-07-31 19:56:08
【问题描述】:
修改 UIImageView 的 layer 属性时,我的结果好坏参半。在UICollectionView 中,我有UICollectionViewCells,其中有一个UIImageView。我希望这些图像看起来像圆圈,因此,在我的 UICollectionViewCell 子类中,我覆盖了 layoutSubviews 并将我的代码放在那里,如下所示:
override func layoutSubviews() {
super.layoutSubviews()
image.layer.cornerRadius = CGRectGetWidth(image.bounds) / 2
image.layer.masksToBounds = true
}
但是,我得到了不可靠的结果。有时,图像是完美的圆形(如预期的那样),但有时它们是带有圆形边缘的正方形,如果您滚动浏览collectionView,它们可能会或可能不会变成圆形。
放置这段代码的最佳位置在哪里?
【问题讨论】:
标签: ios swift uiimageview uicollectionview