具有 stretchableImageWithLeftCapWidth 的 UIImageView 不会拉伸图像 [英] UIImageView with stretchableImageWithLeftCapWidth doesn't stretch image

查看:11
本文介绍了具有 stretchableImageWithLeftCapWidth 的 UIImageView 不会拉伸图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 UIImageView 中拉伸图像 - 但我失败了 :)

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

以下设置:

NIB 文件,带有一个视图和一个附加到该视图的 UIImageView.

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

使用 IBOutlet UIImageView *background 连接到我的班级.

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... :(

我使用的图片高度为 115 像素(我猜这应该足够拉伸了吧?)

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

推荐答案

知道了...(有趣的是,这通常会在提出问题后几秒钟内发生)

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

在 IB 中,我必须将 UIImageView 中的模式设置为 «Scale to fill» 并设置 Autoresize-property

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 ;)

这篇关于具有 stretchableImageWithLeftCapWidth 的 UIImageView 不会拉伸图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆