添加自定义的字体

2016-08-29  本文已影响0人  xiaobei_yang

一、导入所需要的字体到项目工程中

二、确保在Build Phases中能够看到字体,如果没有则需要手动添加进来

三、在info.plist中添加字体信息(Fonts provided by application)

四、确保你的字体名称正确

有的时候你引用的字体名称并不是真的字体名称,你要判断下。

在OC中可以通过下面这段代码输出下

- (void)printAllFont{

           NSArray*fontFamilies = [UIFontfamilyNames];

           for(inti =0; i < [fontFamiliescount]; i++)

           {

                   NSString*fontFamily = [fontFamiliesobjectAtIndex:i];

                   NSArray*fontNames = [UIFontfontNamesForFamilyName:[fontFamiliesobjectAtIndex:i]];

                   NSLog(@"%@: %@", fontFamily, fontNames);

           }

}

输出如下:

五、字体应用

UIFont *customFont = [UIFont fontWithName:@"PingFangTC-Light" size:20];

上一篇 下一篇

猜你喜欢

热点阅读