项目中想使用第三方的字体,在stackoverflow上查询解决办法,也折腾一会,添加成功,示例如下:
1.将xx.ttf字体库加入工程里面
2.在工程的xx-Info.plist文件中新添加一行Fonts provided by application,加上字体库的名称
3.引用字体库的名称,设置字体: [UIFontfontWithName:@"fontname" size:24];
1
2
3
4
5
|
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];
|
如果不知道字体是名称,可以遍历字体进行查询:
1
2
3
4
5
6
7
8
9
|
for
(NSString *fontfamilyname in [UIFont familyNames])
{
NSLog(@
"family:'%@'"
,fontfamilyname);
for
(NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname])
{
NSLog(@
"\tfont:'%@'"
,fontName);
}
NSLog(@
"-------------"
);
}
|
示例Demo下载地址:http://down.51cto.com/3911492/up
参考http://stackoverflow.com/questions/15447558/can-not-include-ttf-font-into-project
本文出自 “新风作浪” 博客,请务必保留此出处http://duxinfeng.blog.51cto.com/3911492/1438678
转载于:https://blog.51cto.com/502317120/1438884