简体   繁体   English

XCode 4.3.2中的自定义字体

[英]Custom font in XCode 4.3.2

I know this subject has been run into the ground, however I have tried every solution I've found on StackOverflow to fix this issue, and its just not working for some reason. 我知道这个主题已经开始,但是我已经尝试了我在StackOverflow上找到的每个解决方案来解决这个问题,并且它因某些原因而无法工作。 I am creating a UILabel programmatically, then using this font. 我以编程方式创建UILabel ,然后使用此字体。 The UILabel is rendering but not in the font I want it to (looks like its defaulting to something) UILabel正在渲染但不是我想要的字体(看起来像是默认的东西)

First I imported two .ttf fonts into the xcode project under a folder called "Resources". 首先,我将两个.ttf字体导入到名为“Resources”的文件夹下的xcode项目中。 The two fonts are Gotham Book and Gotham Book Italic (GothaBoo.ttf, GothaBooIta.ttf) 这两种字体是Gotham Book和Gotham Book Italic(GothaBoo.ttf,GothaBooIta.ttf)

Then, I added a line to the [my app]-Info.plist file called "UIAppFont", added two rows to the array, Item 0 | 然后,我在名为“UIAppFont”的[my app] -Info.plist文件中添加了一行,向数组中添加了两行,Item 0 | String | 字符串| GothaBoo, Item 1 | GothaBoo,第1项| String | 字符串| GothaBooIta. GothaBooIta。

I checked the Target Build Phases, under Copy Bundle Resources, and made sure the two fonts were in there. 我检查了Copy Bundle Resources下的Target Build Phases,并确保这两个字体在那里。

Then, I simply added this code to the viewDidLoad routine: 然后,我只是将此代码添加到viewDidLoad例程:

UILabel *myLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 200, 100)];
myLabel1.text = @"Hello";
myLabel1.backgroundColor = [UIColor clearColor];
myLabel1.font = [UIFont fontWithName: @"GothaBoo" size: 48.0];
myLabel1.textColor = [UIColor blackColor];

[self.view addSubview:myLabel1]; 

No dice. 没有骰子。 What on earth am I doing wrong? 我究竟做错了什么? The project is in Xcode 4.3.2, for the iPad, running 5+ of iOS 该项目采用Xcode 4.3.2,适用于iPad,运行5+以上的iOS

In the array the full filenames must be provided, so instead of Item 0 | 在数组中,必须提供完整的文件名,因此不是Item 0 | String | 字符串| GothaBoo, Item 1 | GothaBoo,第1项| String | 字符串| GothaBooIta you will have to turn this into Item 0 | GothaBooIta你必须把它变成Item 0 | String | 字符串| GothaBoo.ttf, Item 1 | GothaBoo.ttf,第1项| String | 字符串| GothaBooIta.ttf GothaBooIta.ttf

Secondly the filename or the fontname might be different than the name that iOS likes to see in fontWithName: . 其次,文件名或fontname可能与iOS喜欢在fontWithName:看到的名称不同fontWithName: Use Fontbook on your Mac to get the right name, if it still does not work after you have changed the filenames in the .plist. 如果在更改.plist中的文件名后仍然无效,请在Mac上使用Fontbook获取正确的名称。

Beware on the difference of the filename and the fonts name. 请注意文件名和字体名称的区别。 The fonts name will be found in Fontbook. 字体名称将在Fontbook中找到。 In info.plist, it's the filename, and in the code, it's the fonts name. 在info.plist中,它是文件名,在代码中,它是字体名称。

Struggled with this for a long time myself. 我自己挣扎了很久。 Pretty sure that would work. 很确定这会奏效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM