Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ArtOfWarfare

macrumors G3
Original poster
Nov 26, 2007
9,671
6,212
Right now I have a table view with several cells. Each cell has an image in it that's a different size. It's unattractive so I want to change them so they all crop the images to be the same size.

The code I'm trying to do this with is...

Code:
	cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat: @"%@.jpg", cell.textLabel.text]];
	cell.imageView.frame.size.width = 20.0;
	cell.imageView.frame.size.height = 20.0;
	cell.imageView.contentMode = UIViewContentModeScaleToFill;

It's selecting the correct image, and changing the content mode seems to work, but the images all have different widths and so the text labels don't line up right. How can I change all of them to have the same width?

(It gives me the error "Lvalue required as left operand of assignment" on the lines changing the width and height.)
 
frame is a CGRect struct and thus width and height cannot be assigned that way. Either try using CGRectMake or creating a CGRect from the frame, manipulating it, and then reassigning it.
 
Thanks! It now compiles without any errors.

Unfortunately, it doesn't seem to have changed anything.

I am using this code:
Code:
    cell.textLabel.text = [users objectAtIndex:indexPath.row];
	cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat: @"%@.jpg", cell.textLabel.text]];
	cell.imageView.contentMode = UIViewContentModeScaleToFill;
	cell.imageView.bounds = CGRectMake(0,0,20,20);
	cell.imageView.clipsToBounds = YES;

but it's getting me these results:

75ab9002.png


I want the images to all be of the same size.

Also, something curious I found... changing the contentMode property would change how the images were positioned, but not what their dimensions were... IE, the picture for Colin would still be a long rectangle... if you think that's important but don't understand what I mean I can add a picture to explain it better...
 
Yeah, I find I need to resize the image to be cropped as expected. I do this by using a protocol library for image resizing I got from About Objects, Inc. It can be found in the Editable TableView Example on this page.
 
Thank you so much for the help!
Everything displays exactly as I expect and want it to!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.