tags:

views:

381

answers:

1

Hello all,

I am getting some odd behavior from stock table cells, or maybe not odd, maybe I am making some assumptions.

I create the cells as follows:

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

Then I assign an image to the default imageView property. My image usually comes in from a user, so it might be larger than the default size. To take care of this I:

 [cell.imageView setContentMode:UIViewContentModeScaleAspectFit];

which I expected to scale the image for me within the control, but in reality, the images are all over the map.

So, is there a proper way to constrain the image in stock cell types?

Thanks in advance!

+1  A: 

I don't have that problem, but am using:

cell.imageView.image = [[userPics objectAtIndex:indexPath.row] imageScaledToSize:CGSizeMake(44.0, 44.0)]; cell.imageView.contentMode = UIViewContentModeScaleAspectFit;

with a category method:

+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
    UIGraphicsBeginImageContext(newSize);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();        
    UIGraphicsEndImageContext();

    return [newImage retain];
}
- (UIImage *)imageScaledToSize:(CGSize)newSize {
    return [UIImage imageWithImage:self scaledToSize:newSize];
}

And yes, that retain looks suspicious.

Paul Lynch