ios 使用自定義字型
1、下載要使用的自定義字型,格式通常為ttf、otf檔案.這裡假設是nokia.ttf
2、把nokia.ttf檔案匯入xcode的資源中
3、在xxx.plist檔案中新增Fonts provided by application.型別是Array。xxx是你的專案名稱。新增一項,值為“nokia.ttf”.
4、在程式初始化的程式碼中加入以下程式碼:
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
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];
這樣通過日誌可以找出你新增的字型的名稱,我的這個叫“NokiaFontGuYin”
5、使用這個字型.UIFont *font=[UIFont fontWithName:@"NokiaFontGuYin" size:36];