首页 > 代码库 > iOS使用自定义字体

iOS使用自定义字体

1.将准备好的字体文件加入项目中

2.打开Build Phases—Copy Bundle Resources,确保刚添加的字体文件在列表中,否则需要手动加到这里

3.编辑”项目名-Info.plist”文件
(1)addRow—Fonts provided by application

(2)将加入的字体名连同扩展名填在这里

4.在Mac下双击字体文件,在标题栏中找到字体的fontName

5.打印出系统所有的字体名

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 is %@", [fontNames objectAtIndex:indFont]);        }        [fontNames release];    }    [familyNames release];

6.这样就可以使用了[UIFont fontWithName:@"chenweixun-yingxing" size:20];

7.只有文件里配的字才会转换。 

iOS使用自定义字体