tags:

views:

1224

answers:

2

I have a UITableViewCell with a image in it. For some reason whatever UIImage I assign to it, it will not resize.

So I have some simple code like this:

((BubbleCell *)cell).bubbleImage.image = newUIImage;

Here bubbleImage is a UIImageView, a member of BubbleCell(UITableViewCell). When I assign the image to it, it is always the original size. I want to stretch it. How?

I've tried setting the frame of the UIImageView, doesn't help

((BubbleCell *)cell).bubbleImage.frame = CGRectMake(0, 0, 100, 100);

I then actually tried add the UIImageView as a subview directly and that works like this:

[cell addSubview: resizedImageView];

However, I don't want to be adding subview each time cellForRowAtIndexPath is called. It will be hard to layout all the different views inside the cell.

Please help!

+2  A: 

The default contentMode value, UIViewContentModeScaleToFill, should do what you want when you resize the UIImageView frame like:

((BubbleCell *)cell).bubbleImage.frame = CGRectMake(0, 0, 100, 100);

Are you modifying this property anywhere?

Chris Karcher
A: 

in your custom cell class find the property of uiimageview scaletofill like we do in interface builder..then set the property to yes

Rahul Vyas