我的代码几乎正常运行,但有一个问题。
加载表后,图像看起来如下:
但是当我滚动表格时一切都很好:
这里缺少什么?
class ShopTableViewCell: UITableViewCell {
let disposeBag = DisposeBag()
@IBOutlet weak var shopImageView: UIImageView!
@IBOutlet weak var imagesCollectionView: UICollectionView!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var likeButton: UIButton!
@IBOutlet weak var imageContainer: UIView!
override func layoutSubviews() {
super.layoutSubviews()
imageContainer.clipsToBounds = true
imageContainer.layer.cornerRadius = imageContainer.frame.size.width / 2
imageContainer.layer.borderWidth = 1
imageContainer.layer.borderColor = UIColor(hex: "#BDBDBD").CGColor
答案 0 :(得分:5)
这是因为您的imageview的frame属性尚未更新。
您可以创建UIImageView的子类并在那里完成这项工作, 喜欢:
斯威夫特
class CircleImageView: UIImageView {
override func layoutSubviews() {
super.layoutSubviews()
self.layer.borderWidth = 1 / UIScreen.mainScreen().scale
self.layer.borderColor = UIColor(hex: "#BDBDBD").CGColor
self.layer.cornerRadius = self.bounds.size.width/2
self.layer.masksToBounds = true
}
}
目标-C
@implementation CircleImageView
- (void)layoutSubviews {
[super layoutSubviews];
self.layer.borderWidth = 1 / [UIScreen mainScreen].scale;
self.layer.borderColor = [UIColor whiteColor].CGColor;
self.layer.cornerRadius = self.bounds.size.width/2;
self.layer.masksToBounds = YES;
}
@end