项目中想使用第三方的字体,在stackoverflow上查询解决办法,也折腾一会,添加成功,示例如下:
1.将xx.ttf字体库加入工程里面
2.在工程的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.csdn.net/detail/duxinfeng2010/7639683
参考http://stackoverflow.com/questions/15447558/can-not-include-ttf-font-into-project
iOS上使用自定义ttf字体
时间: 2024-10-07 21:54:25