UIImageView with stretchableImageWithLeftCapWidth does not stretch the image

I'm trying to stretch an image in a UIImageView, but I fail :)

The following setting:

NIB file with the view and UIImageView attached to this view.

Wire to my class using IBOutlet UIImageView *background .

Now in my class I will try the following:

 UIImage *bgImage = [[UIImage imageNamed:@"myImage.png"] stretchableImageWithLeftCapWidth:0 topCapHeight:50]; [background setImage: bgImage]; bgFrame = CGRectMake(0, 0, 250, 200); background.frame = bgFrame; 

which should stretch the image vertically - at least what I thought. Alas, it does not work ... :(

The image I'm using is 115 pixels high (should this be enough for stretching, I think?)

+6
iphone stretch uiimageview
source share
2 answers

Got this ... (interestingly, this happens often a few seconds after the question)

In IB, I had to set the mode in UIImageView to "Scale to fill" and set the Autoresize property

What solved the problem ...

Hope someone helps;)

+16
source share

Sometimes it depends on the file. However, I did two things to fix this, and I do not know what the solution was:

  • Open and save the file (I don't think it mattered)
  • Create a file.png file and file@2x.png. (In any case, this should always be done with stretchable images)

After I added the @ 2x file, the image was stretched fine.

+1
source share

All Articles