4
votes

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
Did you ever solve this ?user1349663

1 Answers

0
votes

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!