简体   繁体   English

我如何在UICollectionViewCell中绕过UIImageView?

[英]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.

相关问题 我们如何使用自动布局来舍入 UIImageView - How can we round the UIImageView using autolayouts 如何使用填充单元格的UIImageView初始化自定义UICollectionViewCell? - How do I initialize a custom UICollectionViewCell with a UIImageView that fills the cell? 如何使用IBOutlet UIImageView将自定义对象添加到UICollectionViewCell? - How to add a custom object with IBOutlet UIImageView to a UICollectionViewCell? 如何将UICollectionViewCell中的图像显示到另一个UIImageView? (快速3) - How to show the image in the UICollectionViewCell to another UIImageView? (Swift 3) 如何以编程方式修复带有UIImageView Overlap的UICollectionViewCell - How to fix UICollectionViewCell with UIImageView Overlap Programmatically 如何在tableViewCell中舍入UIImageView的courners - How to round the courners of a UIImageView in a tableViewCell 如何使用自动调整蒙版对UIImageView进行取整? - How to round an UIImageView with Autoresizing Masks? 如何确定何时显示UICollectionViewCell? - How can I determine when a UICollectionViewCell is displayed? iOS:如何更改UICollectionViewCell的方向? - iOS: How can I change the orientation of a UICollectionViewCell? 如何获取UICollectionViewCell的indexPath并保存 - How can I get the indexPath of a UICollectionViewCell and save it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM