ios 使用自定义字体

本文转载至 http://blog.csdn.net/yesjava/article/details/8447596

 

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];

posted @ 2014-09-25 10:16  天牛  阅读(167)  评论(0编辑  收藏  举报