带有stretchableImageWithLeftCapWidth的UIImageView不会拉伸图像
我正在尝试拉伸 UIImageView 中的图像 - 但我惨遭失败:)
以下设置:
带有视图的 NIB 文件和附加到该视图的 UIImageView。
使用 IBOutlet UIImageView *background
连接到我的类。
现在,在我的课堂上,我尝试以下操作:
UIImage *bgImage = [[UIImage imageNamed:@"myImage.png"] stretchableImageWithLeftCapWidth:0 topCapHeight:50];
[background setImage: bgImage];
bgFrame = CGRectMake(0, 0, 250, 200);
background.frame = bgFrame;
应该垂直拉伸图像 - 至少,我是这么想的。唉,它不起作用...:(
我正在使用的图像的高度为 115px(我猜这应该足以拉伸?)
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?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
明白了...(有趣的是,这种情况经常在问问题后几秒钟发生)
在IB中,我必须将 UIImageView 中的模式设置为“缩放以填充”并设置 Autoresize-property
这就是解决问题的方法...
希望对某人有帮助;)
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 ;)
有时这取决于文件,但是我做了两件事来修复它,但我不知道哪一个是解决方案:
在添加@2x 文件后,图像拉伸正常。
Sometimes it depends on the file, However I did two things to fix it and I don't know which was the solution:
After I added the @2x file the image stretched ok.