ios 如何在 Swift 的 Xcode 6 中的 Storyboard 中成功添加图像?

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

How to successfully add an image in Storyboard in Xcode 6 in Swift?

iosobjective-cswiftuiimageviewxcode6

提问by TMM

I'm very new to Xcode (2 days) and so far I'm finding it fairly frustrating. I'm just trying to add an image to my app's ViewController via he Storyboard, but it does not appear on the simulator. Could someone assist me?

我对 Xcode 非常陌生(2 天),到目前为止我发现它相当令人沮丧。我只是想通过 Storyboard 将图像添加到我的应用程序的 ViewController,但它没有出现在模拟器上。有人可以帮助我吗?

回答by Wayne

  1. if you are trying an example project of XCode, you may find a "Images.xcassets" folder in project. Drag your image into this folder.
  2. then go to storyboard, focus on your "Image View".
  3. in the attributes list, "Image" field, you can choose the image in it's drop-down menu.
  4. the try running in simulator
  1. 如果您正在尝试 XCode 的示例项目,您可能会在项目中找到“Images.xcassets”文件夹。将您的图像拖到此文件夹中。
  2. 然后转到故事板,专注于您的“图像视图”。
  3. 在属性列表的“图像”字段中,您可以在其下拉菜单中选择图像。
  4. 在模拟器中运行的尝试

good luck!

祝你好运!

回答by Patrice Gagnon

Here are some details on xcode 10.

以下是有关 xcode 10 的一些详细信息。

  1. Edit the story board, create an image view. Wayne stated, add the image you want in the Images.xcassets.

  2. Click on your image view:

  1. 编辑故事板,创建图像视图。Wayne 说,在 Images.xcassets 中添加你想要的图像。

  2. 单击您的图像视图:

enter image description here

在此处输入图片说明

  1. Do View -> Inspectors -> Show Attribute Inspector
  2. Select the image:
  1. 执行查看 -> 检查器 -> 显示属性检查器
  2. 选择图像:

enter image description here

在此处输入图片说明

回答by williamKeiter

After loading your image in the " Assets.xcassets" folder you will need to find the "Attributes inspector" under your right side inspectors tab. Focus or click on your "Image view" that you have to place as a holder on the storyboard. On the right tab under the attributes inspector (looks like a down arrow next to the ruler) you can select your image from the drop-down selection. You may also want to change Content mode to Aspect Fit while you are there.

在“ Assets.xcassets”文件夹中加载图像后,您需要在右侧检查器选项卡下找到“属性检查器”。聚焦或单击您必须作为故事板固定器放置的“图像视图”。在属性检查器下方的右侧选项卡上(看起来像标尺旁边的向下箭头),您可以从下拉选择中选择您的图像。您可能还想在那里时将内容模式更改为 Aspect Fit。