views:

506

answers:

1

I have a bunch of images I am using for cell's image views, they are all no bigger than 50x50. e.g. 40x50, 50x32, 20x37 .....

When I load the table view, the text doesn't line up because the width of the images varies. Also I would like small images to appear in the centre as opposed to on the left.

Here is the code I am trying inside my 'cellForRowAtIndexPath' method

cell.imageView.autoresizingMask = ( UIViewAutoresizingNone );
cell.imageView.autoresizesSubviews = NO;
cell.imageView.contentMode = UIViewContentModeCenter;
cell.imageView.bounds = CGRectMake(0, 0, 50, 50);
cell.imageView.frame = CGRectMake(0, 0, 50, 50);
cell.imageView.image = [UIImage imageWithData: imageData];

As you can see I have tried a few things, but none of them work.

+2  A: 

Better create an image view and add it as a sub view to the cell.Then you can get the desired frame size.

Warrior
Just tried that, it looks good start but the text in the cells now overlap the images, how do I shift the content view 50 pixels to the right?cell.contentView.bounds = CGRectMake(50, 0, 270, 50); does not have any effect
Robert
Instead of using cell default view, create label and add it as a sub view to the cell, then assign the text to the label text property. By this you can design the cell as per your requirement.
Warrior
This will be more helpful if you want to display title,date,description etc ,more values in a cell.
Warrior
Ok, so basically ill have to remake the cell programmatically. Shouldn't be too hard. Thanks for the help.
Robert