在我的UICollectionViewCell类中,我写了这个: - (void)layoutSubviews { [super layoutSubviews]; self.myImageView.layer.cornerRadius = CGRectGetHeight(self.myImageView.frame) / 2; self.myImageView.layer.masksToBounds = YES;} 但这在所
- (void)layoutSubviews { [super layoutSubviews]; self.myImageView.layer.cornerRadius = CGRectGetHeight(self.myImageView.frame) / 2; self.myImageView.layer.masksToBounds = YES; }
但这在所有情况下都无法正常工作,它看起来像这样:
如果要更改单元格的模型,则应告诉单元格重新计算其布局,以便单元格更改其大小并调用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]; }