Skip to Content
Swift游戏开发经典实例
book

Swift游戏开发经典实例

by Jonathon Manning, Paris Buttfield-Addison
January 2020
Intermediate to advanced
356 pages
6h 4m
Chinese
China Electric Power Press Ltd.
Content preview from Swift游戏开发经典实例
68
2
另外一种添加约束的手段是,按住
Ctrl
+
鼠标左键,从要进行布局的视图
上拖一条线到另外一个视图上。这将弹出一个菜单,允许你选择一个想要的
约束类型。可以选择的类型依赖于两个视图之间的关系。例如,如果你有两
个并排放置的按钮,当你按住
Ctrl
键从一个按钮拖到另一个按钮时,你可能
在弹出菜单中看到“水平间距”的约束。
2.5
导入图片到项目
问题
我们需要将图片导入到
Xcode
并在游戏的菜单界面中使用。
解决方案
当我们创建一个
Xcode
项目时,会同时创建一个资源集。资源集中就包含了图片。
从代码中,我们可以读取资源集中的图片,并将显示在
UI
界面中。
如果项目中没有任何现成的资源集,或者你想创建另外一个资源集,可以选择
File
New
File
,并选择
Resource
Asset Catalog
模板。
在项目的导航窗口中打开某个资源集,你就可以将想用的图片拖到这个资源集中。
在资源集左边的窗格中,通过双击某个图片的名字,你可以给这个图片重新命名。
显示图片的最简单方法是使用
UIImageView
。要创建一个
Image View
,你可以在
Objects Library
窗口中搜索“
image view
”,然后将它拖到故事板中。最后,选中
这个
Image View
,在属性面板中,将
Image
属性修改为图片在资源集中的名字(见
2-18
)。
视图和菜单
69
2
-
18
:为 UIImageView 指定一张图片
也可以在代码中使用图片。例如,假设你在资源集中添加了一张图片,图片名叫作
Spaceship ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

精通機器學習

精通機器學習

Aurélien Géron
FreeBSD® Unleashed

FreeBSD® Unleashed

Brian Tiemann, Michael C. Urban
深入淺出代數

深入淺出代數

Tracey Pilone, Dan Pilone
Swift学习手册

Swift学习手册

Jon Manning, Paris Buttfield-Addison, Tim Nugent

Publisher Resources

ISBN: 9787519840129