在我的 UICollectionViewCell 类中我写了这个:
- (void)layoutSubviews {
[super layoutSubviews];
self.myImageView.layer.cornerRadius = CGRectGetHeight(self.myImageView.frame) / 2;
self.myImageView.layer.masksToBounds = YES;
}
但这并不在所有情况下都能正常工作,它看起来像这样:
我遇到了类似的问题尝试在 TableView Cell 中获取 collectionView https://stackoverflow.com/a/33364092/2893809.
如果您要更改单元格的模型,您应该告诉单元格重新计算其布局,以便单元格更改其大小并调用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];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)