如何在UICollectionViewCell中对UIImageView进行舍入? [英] How I can round UIImageView in UICollectionViewCell?
本文介绍了如何在UICollectionViewCell中对UIImageView进行舍入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的UICollectionViewCell类中,我这样写:
In my UICollectionViewCell class I wrote this:
- (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:
推荐答案
我遇到了类似的问题试图在TableView单元格中获取collectionView 。
如果要更改单元格的模型,应告诉单元格重新计算其布局,以便单元格更改其大小并调用 layoutIfNeeded
。
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
.
- (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];
}
这篇关于如何在UICollectionViewCell中对UIImageView进行舍入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文