UICollectionViewCell 是正方形,但图像是矩形 [英] UICollectionViewCell is square, but image is rectangle
本文介绍了UICollectionViewCell 是正方形,但图像是矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 UICollectionView,其中单元格几乎是正方形,但原始图像是矩形.因此,当我按如下方式显示图像时,它会被剪切.
I am using UICollectionView where cell's are almost square, but original image is rectangle. Therefore, when I display image as follows, it is getting cut.
有没有办法处理这个问题?
Is there a way to handle this issue?
我目前正在研究 Objective-C,但我也想看看 Swift 解决方案.
I am currently working on Objective-C but I am to see Swift solution as well.
cell.productImage 内容模式为 Aspect Fill
cell.productImage content mode is Aspect Fill
cell.productImage.image = [cell.productImage.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
推荐答案
请将此行添加到您的代码中.
Please add this line to your code.
cell.productImage.contentMode = .scaleAspectFit
这篇关于UICollectionViewCell 是正方形,但图像是矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文