IOS第三方字体

项目中想使用第三方的字体,在stackoverflow上查询解决办法,也折腾一会,添加成功,示例如下:

1.将xx.ttf字体库加入工程里面

2.在工程的xx-Info.plist文件中新添加一行Fonts provided by application,加上字体库的名称

3.引用字体库的名称,设置字体: [UIFontfontWithName:@"fontname" size:24];

[objc] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 300, 50)];  
  2. label.text = @"这是一个TEST。123456";  
  3. UIFont *font = [UIFont fontWithName:@"文鼎CS中等線" size:24];  
  4. label.font = font;  
  5. [self.view addSubview:label];  

如果不知道字体名称,可以遍历字体进行查询:

[objc] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. for(NSString *fontfamilyname in [UIFont familyNames])  
  2.   {  
  3.       NSLog(@"family:'%@'",fontfamilyname);  
  4.       for(NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname])  
  5.       {  
  6.           NSLog(@" font:'%@'",fontName);  
  7.       }  
  8.       NSLog(@"-------------");  
  9.   }  



示例Demo下载地址:http://download.csdn.net/detail/duxinfeng2010/7639683

参考http://stackoverflow.com/questions/15447558/can-not-include-ttf-font-into-project

原文地址:https://www.cnblogs.com/worldtraveler/p/4917465.html