PDA

View Full Version : Property Chains?




ArtOfWarfare
Nov 5, 2009, 09:29 PM
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...

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



dejo
Nov 6, 2009, 09:18 AM
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.

ArtOfWarfare
Nov 6, 2009, 02:37 PM
Thanks! It now compiles without any errors.

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

I am using this 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:

http://i212.photobucket.com/albums/cc55/ArtOfWarfare/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...

dejo
Nov 6, 2009, 02:55 PM
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 (http://www.aboutobjects.com/tutorials.html).

ArtOfWarfare
Nov 6, 2009, 08:37 PM
Thank you so much for the help!
Everything displays exactly as I expect and want it to!