Take the 2-minute tour ×

For some reason, I can not seem to change the default position of an image in a grouped tableview cell.

In the cellForRowAtIndexPath method I use the following to load the image:

cell.imageView.image = [UIImage imageWithContentsOfFile:MainImagePath];

I've been experimenting with the following to adjust the position of the image but have had no luck.

cell.contentMode = UIViewContentModeCenter;

I've also tried this with no luck.

cell.imageView.contentMode = UIViewContentModeCenter;
share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

Can you use the frame of the imageView ie: cell.imageView.frame = CGFrameMake(0.0, 0.0, 20.0, 20.0);

or set the center of the imageView with

cell.imageView.center = CGPointMake (20.0, 10.0);


EDITED: Thanks Jonah, I fixed that!

share|improve this answer
Thanks! I think you mean CGPointMake though, not CGMakePoint. –  Jonah Aug 31 '09 at 3:23
add comment

The default layout of UITableViewCell is [imageView][textLabel][accessoryView]. You can't change that.

If you want to arbitrarily position an image in your UITableViewCell you must add a UIImageView to the cell's contentView.

share|improve this answer
Perhaps you're thinking of OS2.2, when the layout was somewhat magical? OS3 definitely gives you access to the underlying UIView pointers, which is specifically so you can treat them as normal views and modify them accordingly, including moving them around. Check the other answers to this question of examples. –  Rob Napier Aug 31 '09 at 3:08
Since UITableViewCell is responsible for the layout of those views, changing their position seems to me to be a hack. It may work, but I don't see any documentation that guarantees that UITableViewCell won't reset its layout, say, when transitioning between edit and non-edit states. On the other hand, Apple's documentation does recommend adding subviews to the cell's contentView, in which case you can guarantee that you are solely responsible for its layout. –  Darren Aug 31 '09 at 5:00
The layout concern is why Apple gave us tableView:willDisplayCell:forRowAtIndexPath:, to give us an opportunity, in a supported way, to perform layout and updates before display. If you have access to the WWDC videos, "Perfecting Your iPhone Table Views" had good discussion of this topic. –  Rob Napier Aug 31 '09 at 17:05
add comment

To move the imageView, you need to change it's frame. The things you're doing are just reconfiguring how it responds to view resizing. Try setting cell.imageView.center to the new center you want.

You should be aware of tableView:willDisplayCell:forRowAtIndexPath:. This is called immediately before displaying the cell, and is your last (and often best) chance to establish layout. tableView:cellForRowAtIndexPath: is called much earlier and its results are cached. So the layout may be wrong by the time it's actually displayed (due to view resizing for instance). That's why we generally do layout in tableView:willDisplayCell:forRowAtIndexPath:.

share|improve this answer
Can you recommend how to set the cell.imageView.center as you recommend? The method described below by Seth causes an "incompatible type for argument" error. Thanks! –  Jonah Aug 31 '09 at 3:16
Oops, seth's code had a small typo, and I got it to build, but it still seems to be ignored. –  Jonah Aug 31 '09 at 3:37
You're setting it in tableView:willDisplayCell:forRowAtIndexPath:? Post the code. –  Rob Napier Aug 31 '09 at 16:52
That doesn't work for the imageView of the cell –  Pascalius May 12 '12 at 10:47
add comment

Your Answer


