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

时间:2012-06-12 12:57:29

标签: ios iphone xcode ios5 xcode4

我在xCode 4.2中添加图片时遇到问题。通过从桌面拖动UIimageviewViewController插入{{1}}时,它将无效。

还有其他可能的方法来添加图片吗?

3 个答案:

答案 0 :(得分:30)

点击文件 - >将图片添加到您的项目中。 “将文件添加到...”。

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

答案 1 :(得分:15)

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

如何执行此操作的教程:http://conecode.com/news/2011/06/ios-tutorial-creating-an-image-view-uiimageview/

答案 2 :(得分:0)

对于xCode 10,首先需要在您的资产目录中添加图片,然后键入以下内容:

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

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

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

import UIKit

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

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