您的位置:首页 > 移动开发 > IOS开发

iOS 修改字体

2015-06-29 13:59 435 查看
iOS开发中经常会修改字体样式,设置成自己想要的字体,总结了一下方法:

1.在程序中先加入这段代码,运行:

[html] view
plaincopy

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];  

将打印出的运行结果,保存到一个.txt文件中,为的是记录下添加新字体前系统原生的字体有哪些。

2.将自己想用的字体(ttf格式或者ttc格式均可)加入到工程Supporting Files目录下。

3.设置plist文件

在plist文件中添加一个Row,“Fonts provided by application”,[b]添加然后添加key为item0,value为你刚才加入的XXX.ttf
。[/b]







4.重新运行程序,执行步骤1的代码,将打印的运行结果保存在另一个.txt文档中,记录下添加新字体后的字体。

5.推荐使用beyond compare这款软件来对比两个.txt文档的区别,找出新添加的字体名,因为新添加的字体名和我们添加的名称会不一致。附上软件的下载网址http://www.pc6.com/mac/118063.html

6.这样就可以在工程中使用新字体了,x x.font = [UIFont fontWithName:@"XXX" size:20.0];

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息