2016-09-04 10 views
5

私のコードはほとんど機能していますが、問題は1つあります。次のようにカスタムUITableViewCellの要素の角の半径を設定する

はとすぐにテーブルがロードされるように、画像のルックスは、以下のとおりです。

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

をしかし、私はテーブルをスクロールすると、すべてが良いです:

But when i scroll the table everything is good

ここに欠けている何か?

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 

答えて

5

あなたの画像ビューのフレームプロパティがまだ更新されていないためです。

あなたは のように、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 
    } 
} 

の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 
関連する問題