我如何能UIImageView在UICollectionViewCell?

在我的UICollectionViewCell类中,我写了这个:

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

但是这在所有情况下都不能正常工作,看起来像这样:

在这里输入图像说明

我遇到了一个类似的问题, 试图在TableView Cell中获取一个collectionView 。

如果你正在改变你的单元格的模型,你应该告诉单元格重新计算它的布局,以便单元格改变其大小并调用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]; }