简体   繁体   English

在Xcode中快速拖动UIImage

[英]Swift drag UIImage in Xcode

I know it is possible to directly drag UIImage in Swift code, which looks like this 我知道可以直接在Swift代码中拖动UIImage ,如下所示

在此处输入图片说明

But somehow I am unable to get it working. 但是以某种方式我无法使其正常工作。

I tried to drag the image@3x.png from resources to code but the dragged image points to some other image, need to know how to get these image literals working. 我试图将image@3x.png从资源拖动到代码中,但是拖动的图像指向其他图像,需要知道如何使这些图像文字正常工作。

you must have the image in your Assets.xcassets folder. 您必须在Assets.xcassets文件夹中具有该图像。 Then after typing Image Literal autocomplete double click the icon and select your image from the collection. 然后,键入Image Literal自动完成后,双击图标并从集合中选择您的图像。 If you have too many images, and you still want to use the Image literals, then comment the ImageLiteral line, and write the exact name into the init of #imageLiteral, like this : // #imageLiteral(resourceName: "NameOfYOurPicture") then uncomment it, and you will have your image there 如果图像太多,仍然要使用Image文字,则注释ImageLiteral行,然后将确切名称写入#imageLiteral的init中,如下所示: // #imageLiteral(resourceName: "NameOfYOurPicture")然后取消注释,您将在其中拥有图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM