项目中想使用第三方的字体,在stackoverflow上查询解决的方法,也折腾一会,加入成功,示比例如以下:
1.将xx.ttf字体库增加project里面
2.在project的xx-Info.plist文件里新加入一行Fonts provided by application,加上字体库的名称
3.引用字体库的名称,设置字体: [UIFontfontWithName:@"fontname" size:24];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 300, 50)];
label.text = @"这是一个TEST。123456";
UIFont *font = [UIFont fontWithName:@"文鼎CS中等線" size:24];
label.font = font;
[self.view addSubview:label];
假设不知道字体名称,能够遍历字体进行查询:
for(NSString *fontfamilyname in [UIFont familyNames])
{
NSLog(@"family:'%@'",fontfamilyname);
for(NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname])
{
NSLog(@"\tfont:'%@'",fontName);
}
NSLog(@"-------------");
}
演示样例Demo下载地址:http://download.youkuaiyun.com/detail/duxinfeng2010/7639683
參考http://stackoverflow.com/questions/15447558/can-not-include-ttf-font-into-project