xcode 如何使用使用XCode5资产目录的切片工具切片的图片

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19357111/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:05:55  来源:igfitidea点击:

How to use images sliced with the slicing tool of the XCode5 assets catalog

iosobjective-cxcodeios7xcode5

提问by Antonio MG

In the assets catalog in the new XCode5 there's a tool to slice your images, I assume this is used for images that are going to be stretched, and it has the same effect as using the resizableImageWithCapInsets: method on a UIImageobject.

在新 XCode5 的资产目录中,有一个工具可以对图像进行切片,我假设它用于将要拉伸的图像,它与resizableImageWithCapInsetsUIImage对象上使用: 方法具有相同的效果。

My question is, once I sliced my image, how do I use it in my code? I just create the image with the size I want and it's stretched automatically using the insents I set in the slicing tool? Or I have to create it using a special way?

我的问题是,一旦我对图像进行了切片,我该如何在我的代码中使用它?我只是创建了我想要的大小的图像,然后使用我在切片工具中设置的 insents 自动拉伸它?或者我必须使用特殊方式创建它?

I haven't found any documentation about it yet.

我还没有找到任何关于它的文档。

回答by Fogmeister

The image slicing in Xcode 5 works with [UIImage imageNamed:@"blah"];. You don't have to do anything in the code. The slicing information is automagically contained in the UIImagethat gets returned.

Xcode 5 中的图像切片适用于[UIImage imageNamed:@"blah"];. 您无需在代码中执行任何操作。切片信息自动包含在UIImage返回的 中。

You can set everything using the asset catalog: retina, iPad, slicing, etc...

您可以使用资产目录设置所有内容:视网膜、iPad、切片等...

Then give the whole set of images a name and just use that name.

然后为整个图像集命名并使用该名称。

Your app will then pull out the correct image from the catalog including all the slicing information.

然后,您的应用程序将从目录中提取正确的图像,包括所有切片信息。