0

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?

Ohad Regev
  • 5,641
  • 12
  • 60
  • 84

1 Answers1

0

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 :).

Community
  • 1
  • 1
Tiago Almeida
  • 14,081
  • 3
  • 67
  • 82
  • I'm 'not fighting the framework' for quite a while and therefor creating custom cells, even if there's no good reason to do so, just for this issue... but that seems elementary. I mean, it's possible to modify any of the other cell UI objects attributes, like the label text color, etc... the only thing that is not working is the image view content mode......... – Ohad Regev Jan 02 '14 at 09:57
  • I actually posted a request in Apple Developer Center... I guess I'm not the first one, but I said to my self "why not..." Let's see what they say... Maybe if everyone posted to them it may have some effect....... – Ohad Regev Jan 02 '14 at 10:22
  • 1
    I know that feeling and I have tried to find the answer myself. But the way I see this issue as a form to force an implementation. Apple gives you a template, but if you want a variation of that template or you want a new template just do your own class. Changing the visual form (or the template) in the cellForRow doesn't seem the proper way to do it. – Tiago Almeida Jan 02 '14 at 11:09