Xcode 8 图像补全 [英] Xcode 8 Image Completion
问题描述
在 Xcode 8 中,您可以在输入时自动完成图像.
问题是:为什么?
我尝试使用建议的结果初始化 UIImage,但它不起作用.
有人知道怎么用吗?
Xcode 8 将自动识别您在 Asset Catalog 中获得的任何图像,并将它们作为建议提供给 UIImage 初始值设定项.
所以基本上你需要做的只是以下(正如你在你的问题中所做的那样,但肯定还有其他事情会打扰它):
let i = voiture//图像名称
然后当你想设置图像时使用 i
.
在幕后,它正在创建如下所示的代码:#imageLiteral(resourceName: "voiture.png")
.但是在源代码编辑器中内联,您只会看到图像的文件名.#imageLiteral
语法只能在 Swift 3 或更高版本上识别.
更新 2
Xcode 11.2.1,这不再出现.
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 1
This functionality remains in Xcode Version 9.0 beta 6 (9M214v)
Update 2
Xcode 11.2.1, this is not appearing anymore.
这篇关于Xcode 8 图像补全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!