您如何以编程方式使用资产目录图像的切片信息? [英] How do you use an asset catalog image's slicing information programmatically?

查看:102
本文介绍了您如何以编程方式使用资产目录图像的切片信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前在项目中有一张图片,我会像这样加载它:

I used to have an image in my project and I would load it like this:

UIImage *image = [[UIImage imageNamed:@"image_name"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0f, 10.0f, 10.0f, 10.0f)];

现在,我将该图像放入XCode 5的新资产目录中,并为其设置切片.如何在代码中使用该图像,以便在加载图像时不必显式调用resizableImageWithCapInsets?

Now I put that image into XCode 5's new asset catalog and I set the slicing for it. How do I use that image in my code so that I don't have to explicitly call resizableImageWithCapInsets when loading the image?

以另一种方式说,如何获取存储在Images.xcassets中的切片信息并将其存储在UIImagecapInsets属性中?

Said another way, how do I take the slicing information stored in Images.xcassets and store it in a UIImage's capInsets property?

还是我在想这一切错吗?

Or am I thinking about this all wrong?

推荐答案

好的,我能够弄清楚这一点.

Ok, I was able to figure this out.

为了自动使用存储在资产目录(Images.xcassets)中的图像中的切片信息,您需要将Deployment Target设置为7.0(或更高版本).

In order to automatically use the slicing information in an image stored in the asset catalog (Images.xcassets) you need to set your Deployment Target to 7.0 (or higher).

希望这可以帮助其他人.

Hope this helps someone else out there.

这篇关于您如何以编程方式使用资产目录图像的切片信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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