ios 通过从文件中拖动图像将图像添加到 xCode
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10997148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding Image to xCode by dragging it from File
提问by Development
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?
有没有其他可能的方法来添加图像?
采纳答案by Sergi Gracia
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/
回答by iMx
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)。
回答by ISS
For xCode 10, first you need to add the image in your assetsCatalogue and then type this:
对于 xCode 10,首先您需要在您的资产目录中添加图像,然后输入:
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.
对于初学者,let 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.
请注意,我没有为图像文件名使用任何扩展名,因为在我的情况下它是一组图像。