UICollectionViewCell is square, but image is rectangle

回眸只為那壹抹淺笑 提交于 2020-01-05 08:58:28

问题


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?

I am currently working on Objective-C but I am to see Swift solution as well.

cell.productImage content mode is Aspect Fill

cell.productImage.image = [cell.productImage.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];


回答1:


Please add this line to your code.

cell.productImage.contentMode = .scaleAspectFit


来源:https://stackoverflow.com/questions/50558996/uicollectionviewcell-is-square-but-image-is-rectangle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!