UIImageView in custom UITableViewCell not respecting Aspect Fit mode

只愿长相守 提交于 2019-12-10 15:41:18

问题


I have a table view that uses a custom UITableViewCell that I created on a NIB. In this custom cell I have a square image view to show logos. The images are already thumbnail-size but they have different sizes (some are squares and some are not).

I simply specified my UIImage in my custom cell to have a View Mode of "Aspect Fit", so as to make all of them display on a square but without losing their aspect ratio.

The problem is that I keep getting an image that fills the height of my row and so the rectangle images are wider than the square images.

Am I missing something basic here? I searched and saw many posts about resizing and scaling but not specific to a UIImageView in a custom UITableViewCell.


回答1:


I had the same problem. The UITableViewCell has a UIImage named "imageView". So if your UIImage variable is also named "imageView", all the code is applied to the default UIImage. Please make sure that the UIImage variable in your custom UITableViewCell is named something different than "imageView"

In my code I had the following line:

cell.imageView.image = UIImage(named: "example")

I have changed the UIImage variable name to "myImageView" and replaced the code above with:

cell.myImageView.image = UIImage(named: "example")

and Aspect fit mode started to work!



来源:https://stackoverflow.com/questions/8085750/uiimageview-in-custom-uitableviewcell-not-respecting-aspect-fit-mode

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