在項目開發中 有時候爲了一些好的UI效果 可能須要自定義字體 app導入字體庫的教程網上有不少 導進去 修改plist文件 而後如何將整個app的字體都換成自定義的字體呢 一個個去寫太麻煩了 因此咱們能夠寫個UIFont的分類:app
而後重寫咱們用到的設置字體的方法,好比經常使用到的:字體
而後重寫對應得方法:spa
這樣 咱們在項目中在經過這兩個方法設置字體的時候 不會直接調用系統方法 而是調用咱們寫的方法 也就是替換成自定義的字體.net
代碼以下:code
.m:blog
// // UIFont+Category.m // font // // Created by 高增洪 on 16/2/25. // Copyright © 2016年 高增洪. All rights reserved. #import "UIFont+Category.h" @implementation UIFont (Category) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation" + (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize { return [UIFont fontWithName:@"HYQiHei-FES" size:fontSize]; } + (UIFont *)systemFontOfSize:(CGFloat)fontSize { return [UIFont fontWithName:@"HYQiHei-DES" size:fontSize]; } #pragma clang diagnostic pop @end
.h:教程
// // UIFont+Category.h // font // // Created by 高增洪 on 16/2/25. // Copyright © 2016年 高增洪. All rights reserved. // #import <UIKit/UIKit.h> @interface UIFont (Category) + (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize; + (UIFont *)systemFontOfSize:(CGFloat)fontSize; @end