@@ -5647,282 +5647,352 @@ we like the fonts big. Then we can hold it all closer and
564756471130
5648564800:58:16,259 --> 00:58:18,993
56495649see our fonts. Well, the way we do that is we go into our
5650- 来看字了。
5650+ 来看字了。我们做到这一点的方式是
5651+
565156521131
5652565300:58:19,062 --> 00:58:22,297
56535654settings on our phone, and one of the settings under general
5655+ 去我们手机的设置里,在通用标签下面
56545656
565556571132
5656565800:58:22,365 --> 00:58:25,433
56575659there is accessibility, and we can say larger text, and
5660+ 有一个辅助功能,在那里我们可以设置更大的字体
56585661
565956621133
5660566300:58:25,502 --> 00:58:27,102
56615664we move the little slider, and
5665+ 我们划一划滑块
56625666
566356671134
5664566800:58:27,170 --> 00:58:29,705
56655669now all the fonts get bigger in all the apps, but
5670+ 就能让所有 app 中的所有字体变大
56665671
566756721135
5668567300:58:29,773 --> 00:58:32,074
56695674only the apps that play this game right, and
5675+ 但也仅限于能正确处理更大字体的 app
56705676
567156771136
5672567800:58:32,142 --> 00:58:35,143
56735679use preferred fonts. So you wanna be one of those apps,
5680+ 它们要用首选字体,那么你就要
56745681
567556821137
5676568300:58:35,212 --> 00:58:37,846
56775684otherwise, you're gonna lose the older folk from
5685+ 让你的 app 也能做到这一点。否则你就会
56785686
567956871138
5680568800:58:37,915 --> 00:58:39,314
56815689your demographic,
5690+ 丢失你的老年用户群体
56825691
568356921139
5684569300:58:39,382 --> 00:58:43,084
56855694of your people buying your app. So it's important to make
5695+ 它们就不会买你的 app 了。所以要确保
56865696
568756971140
5688569800:58:43,153 --> 00:58:46,054
56895699sure that your UI also works when fonts get bigger and
5700+ 当字体变大变小的时候,你的 UI 能够正常工作
56905701
569157021141
5692570300:58:46,122 --> 00:58:50,592
56935704smaller, and the number one way to do that, auto layout.
5705+ 做到这一点的最好的方式是用 auto layout( 自动布局)
56945706
569557071142
5696570800:58:50,661 --> 00:58:52,494
56975709You know that auto layout where you put constraints,
5710+ 我们之前使用约束( constrain) 的时候就用到了 auto layout
56985711
569957121143
5700571300:58:52,563 --> 00:58:55,697
57015714pin things to the edges. You wanna use good auto layout so
5715+ 我们那时将控件控制在边上。你要正确地使用 auto layout
57025716
570357171144
5704571800:58:55,766 --> 00:58:58,800
57055719as fonts get bigger, and the text field gets bigger, other
5720+ 这样当字体变大的时候,它所在的文字空间也变大了
57065721
570757221145
5708572300:58:58,869 --> 00:59:01,836
57095724things push out of the way and it uses the screen real estate
5725+ 其他的东西就被往旁边推了,并且有效地
57105726
571157271146
5712572800:59:01,905 --> 00:59:03,805
57135729properly. So you've only seen a little bit of auto layout.
5730+ 使用屏幕上的空间。你们还没有见过很多 auto layout 的例子
57145731
571557321147
5716573300:59:03,874 --> 00:59:06,608
57175734I'm gonna show you more auto layout at start of Wednesday's
5735+ 在周三的课程的开始,我会向你们展示更多的
57185736
571957371148
5720573800:59:06,676 --> 00:59:07,942
57215739lecture. You're gonna see more and
5740+ auto layout 的例子。之后
57225741
572357421149
5724574300:59:08,011 --> 00:59:09,444
57255744more as the quarter goes by, but
5745+ 你们会见得越来越多
57265746
572757471150
5728574800:59:09,512 --> 00:59:13,047
57295749that's a good way to make it work. Now what if you
5750+ 这是让字体大小正确工作的很好的方式,如果
57305751
573157521151
5732575300:59:13,116 --> 00:59:17,418
57335754either wanna use some other font, some special font that's
5755+ 你既想要用一些其他类型的字体,其他特殊的字体
57345756
573557571152
5736575800:59:17,487 --> 00:59:22,057
57375759something that's maybe part of your marketing or whatever, or
5760+ 比如说是你的用于宣传的字体或者其他什么
57385761
573957621153
5740576300:59:22,126 --> 00:59:25,293
57415764you want it to be bigger, or smaller I guess,
5765+ 而你想让它特定的首选字体的
57425766
574357671154
5744576800:59:25,362 --> 00:59:29,064
57455769than the standard size font that comes with a certain
5770+ 标准大小更大或者更小
57465771
574757721155
5748577300:59:29,133 --> 00:59:32,467
57495774prefered font. Okay, well, UIFont does have a way to
5775+ UIFont 的确有一种
57505776
575157771156
5752577800:59:32,536 --> 00:59:35,837
57535779create a font by name like if you want Helvetica 36 point,
5780+ 用名字来创建字体的方式。比如说你想要大小是 36,字体是 Helvetica
57545781
575557821157
5756578300:59:35,906 --> 00:59:39,841
57575784you can say UIFont( name: "Helvetica", size: 36.0), and
5785+ 你只用写 UIFont( name: "Helvetica", size: 36.0)
57585786
575957871158
5760578800:59:39,909 --> 00:59:42,711
57615789there's also a class called UIFontDescriptor.
5790+ 还有一个类叫做 UIFontDescriptor
57625791
576357921159
5764579300:59:42,780 --> 00:59:44,579
57655794Has a lot of cool ways where you can take a font and
5795+ 它有很多类似于接受一个字体
57665796
576757971160
5768579800:59:44,648 --> 00:59:46,380
57695799say give me the Bold version of this,
5800+ 并返回这个字体的粗体
57705801
577158021161
5772580300:59:46,449 --> 00:59:49,084
57735804give me the Italic version, okay all of that stuff. So
5805+ 或者斜体的函数。类似的那些函数
57745806
577558071162
5776580800:59:49,152 --> 00:59:51,787
57775809you can get your font this way. But if you do your fonts
5810+ 所以你可以以这样的方式获得你的字体。但如果你是
57785811
577958121163
5780581300:59:51,855 --> 00:59:55,190
57815814this way, you still want, when I go into my setting and
5815+ 这样取得的字体,当我进入我的设置
57825816
578358171164
5784581800:59:55,259 --> 00:59:58,427
57855819make my font bigger, you want your font to get bigger, and
5820+ 并让我的字体变大时,你也想让这些字体变大
57865821
578758221165
5788582300:59:58,495 --> 01:00:02,330
57895824look what font size this is, 36. It's fixed.
5825+ 来看看这个字体的大小是多少?36,这是固定的
57905826
579158271166
5792582801:00:02,399 --> 01:00:04,899
57935829So I need to somehow scale this font up
5830+ 所以当用户将它们的字体调大的时候
57945831
579558321167
5796583301:00:04,968 --> 01:00:08,069
57975834if the user has put their slider to bigger, and
5835+ 我要想办法把这个字体变大
57985836
579958371168
5800583801:00:08,137 --> 01:00:11,540
58015839the way you do that is with UIFontMetrics. So you create
5840+ 做到这一点的方法使用 UIFontMetrics
58025841
580358421169
5804584301:00:11,608 --> 01:00:15,710
58055844a UIFontMetrics object for the text style body, footnote,
5845+ 你要为你的文字的字体创建一个
58065846
580758471170
5808584801:00:15,779 --> 01:00:19,080
58095849caption, whatever, and then it has very cool method called
5850+ UIFontMetrics 对象,而它有一个叫做 scaledFont
58105851
581158521171
5812585301:00:19,149 --> 01:00:22,283
58135854scaledFont, and you give it a font, like Helvetica 36,
5855+ 的很酷的函数你给它传递一个字体,比如说 36 大小的 Helvetica
58145856
581558571172
5816585801:00:22,352 --> 01:00:27,121
58175859and it will give you back a new font, Helvetica 42, maybe.
5860+ 而它会返回给你一个新的字体,可能是 42 大小的 Helvetica
58185861
581958621173
5820586301:00:27,190 --> 01:00:31,492
58215864It's scaled based on what the user said. Okay, don't skip
5865+ 它以用户设定的字体大小为基准缩放字体
58225866
582358671174
5824586801:00:31,561 --> 01:00:34,528
58255869this step, otherwise, if you use a custom font,
5870+ 不要跳过这一步,否则当你在用自定义字体的时候
58265871
582758721175
5828587301:00:34,597 --> 01:00:38,333
58295874when people move that slider, your app's not gonna work, and
5875+ 当用户调整字体大小,你的 app 就不能正常运作了
58305876
583158771176
5832587801:00:38,402 --> 01:00:40,935
58335879people are gonna be like, I hate that app.
5880+ 人们就会讨厌你的 app
58345881
583558821177
5836588301:00:41,004 --> 01:00:45,373
58375884I can't see any of the text and it's too small.
5885+ 因为它们看不清这些小的字
58385886
583958871178
5840588801:00:45,442 --> 01:00:48,776
58415889There are also system fonts. We use those so far in our
5890+ 还有一类字体是系统字体,我们在我们的
58425891
584358921179
5844589301:00:48,845 --> 01:00:51,780
58455894concentration demo. That's only for things like button
5895+ Concentration 示例中用过它们了。它们只是用于
58465896
584758971180
5848589801:00:51,848 --> 01:00:54,616
58495899titles, and stuff like that, that's not for user content,
5900+ 类似按钮上的文字或者其它类似的东西的。它们不是用于
58505901
585159021181
5852590301:00:54,685 --> 01:00:57,118
58535904stuff that the user has generated, or requested, or
5905+ 展示给用户或者用户生成的内容的
58545906
585559071182
5856590801:00:57,187 --> 01:00:59,454
58575909something like that. Thos are preferred fonts.
5910+ 那些是首选字体
58585911
585959121183
5860591301:00:59,523 --> 01:01:03,491
58615914System fonts are just like buttons, things like that.
5915+ 系统字体只是用于按钮之类的东西
58625916
586359171184
5864591801:01:03,560 --> 01:01:05,826
58655919What about images? We know how to draw lines and arcs.
5920+ 那么我们该如何画图片呢?我们已经知道如何画直线和弧
58665921
586759221185
5868592301:01:05,895 --> 01:01:06,928
58695924We know how to draw text.
5925+ 知道该如何画文字
58705926
587159271186
5872592801:01:06,997 --> 01:01:11,032
58735929What about drawing images? Just like UILabel for text,
5930+ 那么如何画图片呢,就像 UILabel 是用来装文字的
58745931
587559321187
5876593301:01:11,101 --> 01:01:13,868
58775934there's another one called UIImageView,
5935+ 我们有 UIImageView
58785936
587959371188
5880593801:01:13,937 --> 01:01:17,839
58815939which lets you add an image as a subview. So you could use
5940+ 它可以让你将一个图片添加为它的子视图
58825941
588359421189
5884594301:01:17,907 --> 01:01:20,474
58855944that to draw an image in your view if you want it,
5945+ 所以如果你需要的话,你可以用它来画图片
58865946
588759471190
5888594801:01:20,543 --> 01:01:23,711
58895949just do it as a subview. But if you wanna draw an image
5950+ 只需要将图片添加进子视图。但如果你想在你的
58905951
589159521191
5892595301:01:23,780 --> 01:01:26,481
58935954in your drawRect, you can do that too.
5955+ draw( rect) 画
58945956
589559571192
5896595801:01:26,549 --> 01:01:29,784
58975959You need a UIImage object. A UIImage represents an image,
5960+ 你需要一个 UIImage 对象,一个 UIImage 代表着一张图片
58985961
589959621193
5900596301:01:29,852 --> 01:01:33,287
59015964jpg, gif, whatever kind of image, it represents an image.
5965+ 代表着 jpg,git 之类任意类型的图片
59025966
590359671194
5904596801:01:33,356 --> 01:01:36,457
59055969Now, how do you get an image? There's a bunch of ways to do
5970+ 那么你如何获取一张图片呢?我们有很多方式来做
59065971
590759721195
5908597301:01:36,526 --> 01:01:40,562
59095974it. One way is to drag the jpg file, or whatever, into that
5975+ 其中一种就是将一张图片文件
59105976
591159771196
5912597801:01:40,630 --> 01:01:44,132
59135979Assets.xcassets file. Remember when we're doing our demo,
5980+ 拖进那个 Assets.xcassets 文件中,还记得我们做我们的示例程序
59145981
591559821197
5916598301:01:44,201 --> 01:01:46,300
59175984and I put some things off in supporting files?
5985+ 的时候,我将一些文件拖进那个 supporting files 文件夹吗
59185986
591959871198
5920598801:01:46,369 --> 01:01:48,937
59215989One of the things I threw in there was the place where
5990+ 我拖进去的其中一文件
59225991
592359921199
5924599301:01:49,006 --> 01:01:51,539
59255994the app icon was. Well, you can drag other images in
5995+ 就是装有程序图标的文件,你也可以将其他图片拖进那里
59265996
592759971200
5928599801:01:51,607 --> 01:01:54,308
0 commit comments