iOS 添加自定义的字体 Fonts provided by application

来源:互联网 发布:vocaloid辅助软件 编辑:程序博客网 时间:2024/05/17 22:58

在项目中应用漂亮的字体

1.第一步找到想用的字体的ttf格式,加入到工程的resource目录下



2.

在工程的plist中AddRow,“Fonts provided by application” ,然后添加key为item0,value为你刚才加入的testFont.ttf 。

是这样,可以添加多个,使用的时候写对应字体名字就行。

3.在你的工程就可以直接用了。xx.font = [UIFont fontWithName:@"testFont" size:20.0]

注意,在程序中先加入这段代码,运行:

NSArray *familyNames =[[NSArray alloc]initWithArray:[UIFont familyNames]];     NSArray *fontNames;     NSInteger indFamily, indFont;     NSLog(@"[familyNames count]===%d",[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]);                      }               [fontNames release];  }       [familyNames release];

查看console,以上程序会列出所有的字型,当然也包含“Fonts provided by application”所加的字型,但请注意,名字可能差距很大,要自己找一下



0 0