【发布时间】:2015-09-27 14:33:09
【问题描述】:
所以今天我在尝试使用集合视图并遇到了一个非常有趣的错误。
错误是我拥有的 imageView 圆圈从来都不是完美的,除非我将它们从屏幕上滚动出来。它们的形状类似于带有圆形边缘的菱形。
在我再次上下滚动以使顶部的单元格暂时看不见之后,看不见的单元格现在是完美的圆圈。
这是我的单元类代码:
class FavouritesCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var profilePicutreImageView: UIImageView!
@IBOutlet weak var nameLabel: UILabel!
override var bounds: CGRect {
didSet {
contentView.frame = bounds
}
}
override func layoutSubviews() {
profilePicutreImageView.layer.borderWidth = 2.0
profilePicutreImageView.layer.masksToBounds = false
profilePicutreImageView.layer.cornerRadius = profilePicutreImageView.frame.width/2
profilePicutreImageView.layer.borderColor = UIColor.blackColor().CGColor
profilePicutreImageView.clipsToBounds = true
}
}
关于这可能是什么的任何想法?
更新---这是正在发生的事情的图片
【问题讨论】:
-
通常我使用在initFrame中设置图层属性并设置masksToBounds=true
-
将 mastToBounds 属性设置为 true。
-
恐怕将其设置为 true 没有帮助。您将如何使用 initFrame 进行设置?
标签: ios xcode swift uiimageview uicollectionviewcell