iOS >> UITableViewCell ImageView Property >> ContentMode doesn't have any effect

947 views Asked by At

In many cases using one of the 4 UITableViewCell 'of the shelf' styles is enough for what I need, except for one 'little' annoying thing: The cell.imageView.contentMode property is always set to Scale to Fill. If images have different ratios, it causes the cells labels to be pushed with different x per each Row. It looks ugly...

If I try to fix it in code, let's say in the cellForRowAtIndexPath method, by addressing the property and assigning it to Aspect Fit, I get no warning or error, but it simply does nothing - i.e. it remains with Scale to Fill.

That means, that if I have an app where I'm not responsible for all the images presented in the table view and therefore cannot cut them in the same size - for example, if I wish to allow the user to select images from library or download etc... - I have to use a Custom Cell, even if all it has to have is an Image and a Label.

Does anyone know how to solve this using the default styles, without subclassing UITableViewCell?

1

There are 1 answers

3
Tiago Almeida On

In this SO thread you have a couple of solutions for that.

However, you will find that those solutions are just another way to create a custom cell. Or you need to create an ImageView at runtime or you just create a custom cell. As far as I know it is the right way to do it. I know that is annoying but the time you take to do a custom cell is way shorter than find hacky ways to go around that issue. Don't fight the framework :).