# FontChange ?runtime 字體改變工程下載地址
iOS FontChange
iOS 利用runtime 實現(xiàn)全局字體的改變
創(chuàng)建UIFont的類別
UIFont+GHFont.h,UIFont+GHFont.m
+ (void)load{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
/*利用runtime 實現(xiàn)當(dāng)調(diào)用系統(tǒng)systemFontOfSize:獲取字體的時候,調(diào)用指定的方法ghFontOfSize 從而重新設(shè)置字體*/
kDefultFontName_GH = [UIFont systemFontOfSize:10].fontName;
Class class = [self class];
Method originalMethod = class_getClassMethod(class, @selector(systemFontOfSize:));
Method swizzledMethod = class_getClassMethod(class, @selector(ghFontOfSize:));
method_exchangeImplementations(originalMethod, swizzledMethod);
});
}
+ (UIFont *)ghFontOfSize:(CGFloat)fontSize {
GHFontManager *manager = [GHFontManager sharedFontManager];
NSString *fontName = manager.fontName;
if (fontName == nil) {
fontName = kDefultFontName_GH;
}
return [UIFont fontWithName:fontName? size:fontSize];
}