UIImageView in custom UITableViewCell not respecting Aspect Fit mode
Asked Answered
P

1

4

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.

Pentateuch answered 10/11, 2011 at 20:21 Comment(0)
G
0

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!

Grandiose answered 8/11, 2014 at 10:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.