[翻译]  Adding Image to xCode by dragging it from File

[CHINESE]  通过从File中拖动图像将图像添加到xCode


I'm having trouble adding an image in xCode 4.2. When I'm inserting an UIimageview into the ViewController by dragging it from my desktop, it won't work.

我在xCode 4.2中添加图像时遇到问题。当我通过从桌面拖动它将UIimageview插入ViewController时,它将无法正常工作。

Is there any other possible ways to add an image?

有没有其他可能的方法来添加图像?

3 个解决方案

#1


16  

You can't add image from desktop to UIimageView, you only can add image (dragging) into project folders and then select the name image into UIimageView properties (inspector).

您无法将图像从桌面添加到UIimageView,您只能将图像(拖动)添加到项目文件夹中,然后选择名称图像到UIimageView属性(检查器)。

Tutorial on how to do that: http://conecode.com/news/2011/06/ios-tutorial-creating-an-image-view-uiimageview/

关于如何做到这一点的教程:http://conecode.com/news/2011/06/ios-tutorial-creating-an-image-view-uiimageview/

#2


27  

Add the image to Your project by clicking File -> "Add Files to ...".

单击文件 - >“将文件添加到...”将图像添加到项目中。

Then choose the image in ImageView properties (Utilities -> Attributes Inspector).

然后在ImageView属性中选择图像(Utilities - > Attributes Inspector)。

#3


-1  

For xCode 10, first you need to add the image in your assetsCatalogue and then type this:

对于xCode 10,首先需要在assetsCatalogue中添加图像,然后键入:

let imageView = UIImageView(image: #imageLiteral(resourceName: "type the name of your image here..."))

For beginners, let imageView is the name of the UIImageView object we are about to create.

对于初学者,让imageView是我们即将创建的UIImageView对象的名称。

An example for embedding an image into a viewControler file would look like this:

将图像嵌入viewControler文件的示例如下所示:

import UIKit

class TutorialViewCotroller: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        let imageView = UIImageView(image: #imageLiteral(resourceName: "intoImage"))
        view.addSubview(imageView)
    }
}

Please notice that I did not use any extension for the image file name, as in my case it is a group of images.

请注意,我没有使用图像文件名的任何扩展名,因为在我的情况下,它是一组图像。


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号