enter image description here我在 Collection View 单元格内的 UIView 中有一个 UIImageView,但即使我做了所有约束(顶部、底部、左侧、右侧),图像的高度也比它的 super View 大。 我该如何解决?
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width:DeviceSize.screenWidth - 32, height: DeviceSize.screenWidth/2)
}
最佳答案
设置,
imageView.contentMode = .scaleAspectFit //you can change it as per your requirement..
imageView.clipToBounds = true
除了以编程方式进行,您还可以在 storyboard
本身中设置它们,即
关于ios - 如何修复 UICollectionViewCell 中的图像高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56630802/