創建UIFont的類別 UIFont+GHFont.h,UIFont+GHFont.m
(void)load{ static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ /利用runtime 實現當調用系統systemFontOfSize:獲取字體的時候,調用指定的方法ghFontOfSize 從而重新設置字體/ 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]; }
QQ:329750074
DEMO下載地址
【iOS 利用runtime 實現全局字體的改變】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!