Comment je peux arrondir UIImageView dans UICollectionViewCell?

Dans ma class UICollectionViewCell, j'ai écrit ceci:

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

Mais cela ne fonctionne pas correctement dans tous les cas, il apparaît comme ceci:

entrez la description de l'image ici

J'ai fait face à un problème similaire en essayant d'get une collectionView dans une cellule TableView .

Si vous modifiez le model de votre cellule, vous devez indiquer à la cellule de recalculer sa disposition afin que la cellule change de taille et appelle 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]; }