How I can round UIImageView in UICollectionViewCell?

爷,独闯天下 提交于 2019-12-07 17:24:46

问题


In my UICollectionViewCell class I wrote this:

- (void)layoutSubviews {
    [super layoutSubviews];
    self.myImageView.layer.cornerRadius  = CGRectGetHeight(self.myImageView.frame) / 2;
    self.myImageView.layer.masksToBounds = YES;
}

But this does not work correctly in all cases, it appears like this:


回答1:


I faced a similar problem trying to get a collectionView inside a TableView Cell.

If you are changing your cell's model you should tell the cell to recalculate its layout so the cell changes its size and calls layoutIfNeeded.

 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
              cellForItemAtIndexPath:(NSIndexPath *)indexPath
         UICollectionViewCell*cell = ...
         // Do your stuff here to configure the cell
         // Tell the cell to redraw its contentView        
         [cell layoutIfNeeded];
    }


来源:https://stackoverflow.com/questions/33733262/how-i-can-round-uiimageview-in-uicollectionviewcell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!