[英]How I can round UIImageView in UICollectionViewCell?
In my UICollectionViewCell class I wrote this: 在我的UICollectionViewCell类中,我写了这个:
- (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: 但这在所有情况下都无法正常工作,它看起来像这样:
I faced a similar problem trying to get a collectionView inside a TableView Cell . 我在尝试在TableView Cell中获取collectionView时遇到了类似的问题。
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
. 如果要更改单元格的模型,则应告诉单元格重新计算其布局,以便单元格更改其大小并调用
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];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.