如何在 XCode 中将图像添加到界面构建器中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9949629/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:50:24  来源:igfitidea点击:

How do I add images into interface builder in XCode?

xcodeinterface-builder

提问by Justin Copeland

I dragged five images into my supporting files folder.

我将五个图像拖到我的支持文件文件夹中。

I tried to drag and drop them from my file panel into the interface builder, but XCode would not let me do so. Do I need to perform an action with something called an "UIImageView"?

我试图将它们从我的文件面板拖放到界面构建器中,但 XCode 不允许我这样做。我是否需要使用名为“UIImageView”的东西来执行操作?

How do I add images into interface builder? Thank you, this is my first time programming in XCode.

如何将图像添加到界面构建器中?谢谢,这是我第一次用 XCode 编程。

回答by Mick MacCallum

If you drag and drop the images from the "Media Library" section of the Utilities panel directly onto your view, they will automatically create the UIImageViewand allow you to drop them directly in as illustrated below.

如果您将“实用工具”面板的“媒体库”部分中的图像直接拖放到您的视图上,它们将自动创建UIImageView并允许您将它们直接放入,如下图所示。

enter image description here

在此处输入图片说明

回答by Oscar Gomez

You can select your UIImageViewin Interface Builder, and then open the attributes inspector, to do so in XCode you will see 3 types of views select the one that opens the panel to the right, then it is the one that looks kinda like a shield, expand Image View, and you can select your image in the drop down box for "Image".

你可以UIImageView在 Interface Builder 中选择你的,然后打开属性检查器,在 XCode 中你会看到 3 种类型的视图,选择打开右侧面板的一种,然后它看起来有点像盾牌,展开图像视图,您可以在“图像”下拉框中选择您的图像。

回答by Mikayil Abdullayev

There's no way you drag and drop plain images into IB. To display images you need a UIImageView object. That's what you will find in Interface Builder. Just drag and drop a UIImageView into the view of controller. UIImageView has image property.From the drop down list of that property you will find the images you added to your project group.Pick any image and that's it. Do not forget that UIImageView can hold only one image in its image property. It's not an NSArray of images. So in case you want to kinda"import" all the images, you'll have to add that many image views to your view.

您无法将普通图像拖放到 IB 中。要显示图像,您需要一个 UIImageView 对象。这就是您将在 Interface Builder 中找到的内容。只需将 UIImageView 拖放到控制器的视图中即可。UIImageView 具有图像属性。从该属性的下拉列表中,您将找到添加到项目组中的图像。选择任何图像即可。不要忘记 UIImageView 只能在其 image 属性中保存一张图像。它不是图像的 NSArray。因此,如果您想“导入”所有图像,则必须将那么多图像视图添加到您的视图中。

回答by TheMoon2000

It's not that hard for me. You just first get the image into Xcode and then open interface builder. Then find the image well object in the library and drag it into the window to where you want it to be. Finally just type in the name of the image WITHOUT EXTENSION into the image text box on the right side in image view.

这对我来说并不难。您只需先将图像放入 Xcode,然后打开界面构建器。然后在库中找到图像井对象并将其拖到窗口中到您想要的位置。最后,只需在图像视图右侧的图像文本框中输入没有扩展名的图像名称。