IOS如何使用第三方字體

一、從網上下載所需字體的TTF文件。將字體所對應的TTF文件拖入項目中。app

二、而後在info.plist中添加一個新的鍵Fonts provided by application, NSArray類型的, 在其對應的item裏面的string值爲**.TTF,如圖:ide


三、接下來就是要知道對應字體的名字FontName了。一個字體文件包括如下幾個內容:文件名、字體名稱、字體具體名稱,咱們只有文件名,不知道字體名稱是什麼,更不知道具體的名稱,那麼咱們就須要寫代碼得到具體的字體名稱。方法以下:字體


  1. NSArray *familys = [UIFont familyNames];  spa

  2.       

  3.     for (int i = 0; i < [familys count]; i++)  code

  4.     {  string

  5.         NSString *family = [familys objectAtIndex:i];  it

  6.         NSLog(@"=====Fontfamily:%@", family);  io

  7.         NSArray *fonts = [UIFont fontNamesForFamilyName:family];  class

  8.         for(int j = 0; j < [fonts count]; j++)  object

  9.         {  

  10.             NSLog(@"***FontName:%@", [fonts objectAtIndex:i]);  

  11.         }  

  12.     }  


看一下打印結果吧?

2013-04-10 17:37:09.758 FontDemo[3336:c07] =====Fontfamily:Thonburi

2013-04-10 17:37:10.442 FontDemo[3336:c07] ***FontName:Thonburi-Bold

2013-04-10 17:37:10.827 FontDemo[3336:c07] ***FontName:Thonburi-Bold

2013-04-10 17:37:12.403 FontDemo[3336:c07] =====Fontfamily:Snell Roundhand

2013-04-10 17:37:12.404 FontDemo[3336:c07] ***FontName:SnellRoundhand-Black

2013-04-10 17:37:12.404 FontDemo[3336:c07] ***FontName:SnellRoundhand-Black

2013-04-10 17:37:12.405 FontDemo[3336:c07] ***FontName:SnellRoundhand-Black

四、如今能夠知道文字包裏面的字體名稱了吧?接下來使用就能夠咯:

  1. self.lblTitle.font = [UIFont fontWithName:@"SnellRoundhand-Bold" size:17.0]; 

相關文章
相關標籤/搜索