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