erotsppa
erotsppa

Reputation: 15021

How to stretch a UIImage into a UIImageView?

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!

Upvotes: 2

Views: 4829

Answers (2)

Rahul Vyas
Rahul Vyas

Reputation: 28720

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

Upvotes: 0

Chris Karcher
Chris Karcher

Reputation: 2292

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?

Upvotes: 5

Related Questions