2016-09-04 16 views
5

Mã của tôi gần như đang hoạt động, nhưng có một vấn đề.Đặt bán kính góc của một phần tử trong UITableViewCell

Ngay sau khi bảng được nạp, hình ảnh trông như sau:

As soon as the table is loaded, images looks are as follows

Nhưng khi tôi di chuyển bảng mọi thứ đều tốt:

But when i scroll the table everything is good

gì là mất tích ở đây ?

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 

Trả lời

5

Đó là vì thuộc tính khung của lần xem hình ảnh của bạn chưa được cập nhật.

Bạn có thể tạo một lớp con của UIImageView và làm công việc mà ở đó, như:

Swift

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 
    } 
} 

Objective-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 
Các vấn đề liên quan