UIImageView with stretchableImageWithLeftCapWidth doesn't stretch image

不想你离开。 提交于 2019-11-30 04:45:31

问题


I'm trying to stretch an Image in a UIImageView - but I fail miserably :)

Following setup:

NIB-File with a view and a UIImageView attached to this view.

Wired to my class using IBOutlet UIImageView *background.

Now, in my class I 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, that's what I thought. Alas, it's not working... :(

The image I'm using has a height of 115px (which should be enough for the stretch, I guess?)


回答1:


Got it... (interesting that this happens often just seconds after asking the question)

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

That's what solved the problem...

Hope that helps somebody ;)




回答2:


Sometimes it depends on the file, However I did two things to fix it and I don't know which was the solution:

  • Open and resave the file (I don't think this made the difference)
  • Create the file.png and file@2x.png file. (Anyway this should always be done with stretchable images)

After I added the @2x file the image stretched ok.



来源:https://stackoverflow.com/questions/3401252/uiimageview-with-stretchableimagewithleftcapwidth-doesnt-stretch-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!