iOS中使用第三方字體

項目中想使用第三方的字體,在stackoverflow上查詢解決辦法,也折騰一會,添加成功,示例如下:


1.將xx.ttf字體庫加入工程裏面

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




3.引用字體庫的名稱,設置字體: [UIFontfontWithName:@"fontname" size:24];


[objc] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(1010030050)];  
  2. label.text = @"這是一個TEST。123456";  
  3. UIFont *font = [UIFont fontWithName:@"文鼎CS中等線" size:24];  
  4. label.font = font;  
  5. [self.view addSubview:label];  


如果不知道字體名稱,可以遍歷字體進行查詢:

[objc] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. for(NSString *fontfamilyname in [UIFont familyNames])  
  2.   {  
  3.       NSLog(@"family:'%@'",fontfamilyname);  
  4.       for(NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname])  
  5.       {  
  6.           NSLog(@"\tfont:'%@'",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


發佈了105 篇原創文章 · 獲贊 73 · 訪問量 21萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章