【问题标题】:Adding Image to xCode by dragging it from File通过从文件中拖动图像将图像添加到 xCode
【发布时间】:2012-06-15 08:44:23
【问题描述】:

我在 xCode 4.2 中添加图像时遇到问题。当我将UIimageview 从我的桌面拖动到ViewController 中时,它不起作用。

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

【问题讨论】:

  • 首先将图片文件添加到你的项目中

标签: ios iphone xcode ios5 xcode4


【解决方案1】:

通过单击“文件”->“将文件添加到...”将图像添加到您的项目。

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 链接已损坏。
    【解决方案3】:

    对于 xCode 10,首先您需要在 assetsCatalogue 中添加图片,然后输入:

    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)
        }
    }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-28
      • 2023-03-28
      • 1970-01-01
      相关资源
      最近更新 更多