XCode 4.3.2中的自定义字体 [英] Custom font in XCode 4.3.2

查看:162
本文介绍了XCode 4.3.2中的自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个主题已经运行到底,但是我已经尝试了我在StackOverflow上找到的每个解决方案来解决这个问题,而且由于某种原因它不工作。我正在以编程方式创建一个 UILabel ,然后使用这个字体。 UILabel 正在呈现,但不是我想要的字体(看起来像是默认的)



我将两个.ttf字体导入到名为Resources的文件夹下的xcode项目中。这两个字体是Gotham书和Gotham书斜体(GothaBoo.ttf,GothaBooIta.ttf)

然后,我添加了一行到[我的应用程序] -Info.plist文件名为UIAppFont,在数组中添加了两行,Item 0 |字符串| GothaBoo,项目1 |字符串| GothaBooIta。



我在Copy Bundle Resources下勾选了Target Build Phases,并确定两个字体都在那里。


$ b $然后,我简单地将这段代码添加到viewDidLoad例程中:

$ p $ U $ c $ UILabel myLabel1 = [[UILabel alloc] initWithFrame :CGRectMake(50,100,200,100)];
myLabel1.text = @Hello;
myLabel1.backgroundColor = [UIColor clearColor];
myLabel1.font = [UIFont fontWithName:@GothaBoosize:48.0];
myLabel1.textColor = [UIColor blackColor];

[self.view addSubview:myLabel1];

没有骰子。我究竟做错了什么?该项目是在Xcode 4.3.2,为iPad,运行iOS的5+。解决方案

在数组中,完整的文件名必须被提供,而不是Item 0 |字符串| GothaBoo,项目1 |字符串| GothaBooIta你将不得不把这个变成Item 0 |字符串| GothaBoo.ttf,项目1 |字符串| GothaBooIta.ttf
$ b其次,文件名或字体名可能与iOS在 fontWithName:。使用Mac上的Fontbook取得正确的名字,如果在你改变.plist中的文件名后仍然不起作用的话。


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. I am creating a UILabel programmatically, then using this font. The UILabel is rendering but not in the font I want it to (looks like its defaulting to something)

First I imported two .ttf fonts into the xcode project under a folder called "Resources". The two fonts are Gotham Book and 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 | String | GothaBoo, Item 1 | String | GothaBooIta.

I checked the Target Build Phases, under Copy Bundle Resources, and made sure the two fonts were in there.

Then, I simply added this code to the viewDidLoad routine:

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

解决方案

In the array the full filenames must be provided, so instead of Item 0 | String | GothaBoo, Item 1 | String | GothaBooIta you will have to turn this into Item 0 | String | GothaBoo.ttf, Item 1 | String | GothaBooIta.ttf

Secondly the filename or the fontname might be different than the name that iOS likes to see in 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.

这篇关于XCode 4.3.2中的自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆