1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Property Chains?

Discussion in 'iPhone/iPad Programming' started by ArtOfWarfare, Nov 5, 2009.

  1. macrumors 603


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


    Staff Member

    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.
  3. macrumors 603


    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:


    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...
  4. Moderator


    Staff Member

    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.
  5. macrumors 603


    Thank you so much for the help!
    Everything displays exactly as I expect and want it to!

Share This Page