一、從網上下載所需字體的TTF文件。將字體所對應的TTF文件拖入項目中。app
二、而後在info.plist中添加一個新的鍵Fonts provided by application, NSArray類型的, 在其對應的item裏面的string值爲**.TTF,如圖:ide
三、接下來就是要知道對應字體的名字FontName了。一個字體文件包括如下幾個內容:文件名、字體名稱、字體具體名稱,咱們只有文件名,不知道字體名稱是什麼,更不知道具體的名稱,那麼咱們就須要寫代碼得到具體的字體名稱。方法以下:字體
NSArray *familys = [UIFont familyNames]; spa
for (int i = 0; i < [familys count]; i++) code
{ string
NSString *family = [familys objectAtIndex:i]; it
NSLog(@"=====Fontfamily:%@", family); io
NSArray *fonts = [UIFont fontNamesForFamilyName:family]; class
for(int j = 0; j < [fonts count]; j++) object
{
NSLog(@"***FontName:%@", [fonts objectAtIndex:i]);
}
}
看一下打印結果吧?
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
四、如今能夠知道文字包裏面的字體名稱了吧?接下來使用就能夠咯:
self.lblTitle.font = [UIFont fontWithName:@"SnellRoundhand-Bold" size:17.0];