我如何在UICollectionViewCell中绕过UIImageView?

时间:2015-11-16 10:36:00

标签: ios uiimageview calayer layoutsubviews

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

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

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

enter image description here

1 个答案:

答案 0 :(得分:7)

我遇到了类似的问题trying to get a collectionView inside a TableView Cell

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