UIFont「自定义字体」
2016-06-06 本文已影响138人
LuisX
UIFont
iOS自定义字体
字体文件导入工程1.将字体文件导入工程(.ttf)
确保字体文件添加成功2.打开Build Phases -> Copy Bundle Resources,确定字体文件已经添加
编辑info.plist3.编辑info.plist文件,添加Fonts provided by application并将字体文件加入到该项数组中
4.使用如下代码显示所有字体名称
//显示所有字体
- (void)showAllFontBank{
NSArray *familyNames =[[NSArray alloc]initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
NSLog(@"[familyNames count]===%lu",(unsigned long)[familyNames count]);
for(indFamily=0;indFamily<[familyNames count];++indFamily){
NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
fontNames =[[NSArray alloc]initWithArray:[UIFont fontNamesForFamilyName:[familyNames objectAtIndex:indFamily]]];
for(indFont=0; indFont<[fontNames count]; ++indFont){
NSLog(@"Font name: %@",[fontNames objectAtIndex:indFont]);
}
}
}
找到添加的字体5.控制台输出中寻找字体名称
(字体名称可能和字体文件名不一致)
6.使用UIFont调用字体
[UIFont fontWithName:@"FZLTXHKM" size:17];
[UIFont fontWithName:@"FZLTHJW--GB1-0" size:17];