Take the 2-minute tour ×

I have this UIImageview, with an image. It's a small image, that is tiled with the


method. It's very useful to do screen size independent images, and it works well: if I programmatically change the frame size of the UIImageview, the image inside is not stretched, but repeated, so the pixels remain pixels.

Now, when I do a

self.myImageView.transform=CGAffineTransformMakeScale(5.0, 5.0);

to the UIImageview containing/displaying that image, I notice that the image now actually is stretched.

I tried reloading the image into the view, but that doesn't seem to help.

The UIImageView is in the "Scale to Fill" mode.

The question in short is: how do I make sure the image is not stretched, but tiled after the transformation?

UPDATE: the reason for using CGAffineTransformMakeScale is, that I want to grow/shrink the image(view) relative to its center.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Instead of applying the transform direct to the view, use CGRectApplyAffineTransform and transform the image view frame. This won't work well for all possible transformations though so limit to translation and scale.

share|improve this answer
That works fine, but the reason why I used CGAffineTransformMakeScale in the first place, was to do a scaling from the center: growing/shrinking the image(view), while keeping the center of the view pinned. I will edit my original question. –  Sjakelien May 7 '13 at 13:50
In that case your best option may be simply to use CGRectInset. –  Wain May 7 '13 at 14:31
Brilliant, thanks! –  Sjakelien May 7 '13 at 17:10
add comment

Your Answer


