lable.font = UIFont.init(name: "字体名字", size: 18) :同时设置字体大小html
self.nameLable.setSubstituteFontName("设置字体名字")app
当设置字体系统库中没有时,使用第三方字库(格式:ttf)ide
1>将字体库导入工程中字体
2>在plist文件中添加:“Fonts provided by application”(Array类型)value:字体文件名.ttfhtm
就可使用上边方法设置字体blog
字体库比较大时,无法所有覆盖,就应该使用读取字体的方式:ip
1>添加CoreText字库,导入头文件#import "CoreText/CoreText.h"it
-(UIFont*)customFontWithPath:(NSString*)path size:(CGFloat)sizeio
{import
NSURL *fontUrl = [NSURL fileURLWithPath:path];
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL((__bridge CFURLRef)fontUrl);
CGFontRef fontRef = CGFontCreateWithDataProvider(fontDataProvider);
CGDataProviderRelease(fontDataProvider);
CTFontManagerRegisterGraphicsFont(fontRef, NULL);
NSString *fontName = CFBridgingRelease(CGFontCopyPostScriptName(fontRef));
UIFont *font = [UIFont fontWithName:fontName size:size];
CGFontRelease(fontRef);
return font;
}
附加:http://www.cnblogs.com/woaixixi/p/5590426.html