Xcode 8图像完成 [英] Xcode 8 Image Completion
问题描述
在Xcode 8中,您可以在输入时自动完成图像。
问题是:为什么?
我尝试使用建议的结果初始化UIImage,但它不起作用。
有谁知道如何使用它?
Xcode 8将自动识别您在资产目录中获得的任何图像,并在UIImage初始化程序内提供它们作为建议。
所以基本上你需要做的就是以下(正如你在你的问题中所做的那样,但必须有一些令人不安的事情):
让i = voiture //图片名称
当您想要设置图像时,只需使用 i
。
在引擎盖下,它创建的代码如下所示: #imageLiteral(resourceName:voiture.png)
。但是在源编辑器中内联,您只需看到图像的文件名。 #imageLiteral
语法仅在 Swift 3 或更高版本中识别。
In Xcode 8, you have images autocompleted while typing.
Question is : Why?
I tried to init UIImage with the suggested result, but it doesn't work.
Does anyone know how to use it ?
Xcode 8 will automatically recognize any images you’ve got in an Asset Catalog and offer them up as a suggestion inside of a UIImage initializer.
So basically what you need to do is just the following (as you have done in your question, but there must be something else that´s disturbing it):
let i = voiture // image name
And then just use i
when you want to set an image.
Under the hood it’s creating code that looks like this: #imageLiteral(resourceName: "voiture.png")
. But inline in the source editor, you’ll just see the file name of the image. The #imageLiteral
syntax is only recognised on Swift 3 or later.
Here is a demonstration video link where I do this and here is a link to a sample project that I created.
Note that you need to click on the instellisense suggestion so that you see a thumbnail of the image in the code and then the image name.
Update:
This functionality remains in Xcode Version 9.0 beta 6 (9M214v)
这篇关于Xcode 8图像完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!