当前位置 : 主页 > 手机开发 > ios >

ios – 如何在UICollectionViewCell中绕过UIImageView?

来源:互联网 收集:自由互联 发布时间:2021-06-11
在我的UICollectionViewCell类中,我写了这个: - (void)layoutSubviews { [super layoutSubviews]; self.myImageView.layer.cornerRadius = CGRectGetHeight(self.myImageView.frame) / 2; self.myImageView.layer.masksToBounds = YES;} 但这在所
在我的UICollectionViewCell类中,我写了这个:

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

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

enter image description here

我遇到了类似的问题 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];
    }
网友评论