Q: Autoresizing masks in a UITableViewCell I'm creating an app that has the following screen.  However, I can't get the images to line up as I'd like.  What I want is for the images to be as large as possible, without being distorted and without them covering the text or leaking outside of the cell.  I think I have the code correct for shrinking the images; however, I can't figure out what autoresizing mask to put on them.

Here is the relevant code:  
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Prototype Cell"];
    if(!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Prototype Cell"];
    }
    Restaurant *restaurantForIndex = [self.restaurants objectAtIndex:indexPath.row];
    UILabel *label = [[UILabel alloc] init];
    label.backgroundColor = [UIColor greenColor];
    label.text = restaurantForIndex.name;
    label.font = [UIFont fontWithName:CELL_FONT_NAME size:CELL_FONT_SIZE];
    [cell.contentView addSubview:label];

    cell.backgroundColor = [UIColor whiteColor];

    UIImage *image = [restaurantForIndex getLogo];
    if(image.size.height > CELL_HEIGHT - 2 *CELL_Y_BUFFER)
    {
        float scale = (CELL_HEIGHT - 2 * CELL_Y_BUFFER) / image.size.height;
        image = [UIImage scaleImage:image toSize:CGSizeMake(image.size.width * scale, CELL_HEIGHT - 2 * CELL_Y_BUFFER)];
    }
    float textWidth = [label.text sizeWithFont:[UIFont fontWithName:CELL_FONT_NAME size:CELL_FONT_SIZE]].width;
    label.frame = CGRectMake(CELL_X_BUFFER, CELL_Y_BUFFER, textWidth, cell.contentView.frame.size.height - 2 * CELL_Y_BUFFER);
    label.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    if(label.frame.origin.x + textWidth + NAME_LOGO_BUFFER + image.size.width + CELL_X_BUFFER > cell.contentView.frame.size.width)
    {
        float newImageWidth = cell.contentView.frame.size.width - (label.frame.origin.x + textWidth + NAME_LOGO_BUFFER + CELL_X_BUFFER);
        float scale = newImageWidth / image.size.width;
        image = [UIImage scaleImage:image toSize:CGSizeMake(newImageWidth, image.size.height * scale)];
    }
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    float xOrigin = cell.contentView.frame.size.width - image.size.width - CELL_X_BUFFER;
    float yOrigin = (cell.contentView.frame.size.height - image.size.height) / 2 ;
    float width = image.size.width;
    float height = image.size.height;
    imageView.frame = CGRectMake(xOrigin, yOrigin, width, height);

    //IMPORTANT LINE OF CODE HERE
    imageView.autoresizingMask =  UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin  | UIViewAutoresizingFlexibleLeftMargin;
    [cell.contentView addSubview:imageView];
    return cell;
}

Just a few notes about the code: where ever you see a capitalized BUFFER word it is just a constant so that subviews don't touch the very edge of the cell.
