iOS 添加字体

1. 将字体(ttf 文件)导入项目。

2. 在项目plist 文件里的 Fonts provided by application 添加新导入的字体。

3. 代码中的调用

[aLabel setFont:[UIFont fontWithName:@"a-font-name" size 100]];

注意  fontWithName 要写字体名而不是字体文件名。比如你有一个 century_gothic.ttf 文件,字体名应该是 CenturyGothic。

获取字体名的方法:

for (NSString* family in [UIFont familyNames])
{
    NSLog(@"%@", family);
        
    for (NSString* name in [UIFont fontNamesForFamilyName: family])
    {
        NSLog(@"  %@", name);
    }
}

 

参考文章:

http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/

 

posted @ 2015-05-01 00:20  davesuen  阅读(201)  评论(0编辑  收藏  举报