修改整个app的字体

在项目开发中  有时候为了一些好的UI效果  可能需要自定义字体  app导入字体库的教程网上有很多 导进去 修改plist文件  然后如何将整个app的字体都换成自定义的字体呢  一个个去写太麻烦了  所以我们可以写个UIFont的分类:

然后重写我们用到的设置字体的方法,比如常用到的:

然后重写对应得方法:

这样  我们在项目中在通过这两个方法设置字体的时候  不会直接调用系统方法  而是调用我们写的方法  也就是替换成自定义的字体

代码如下:

.m:

//
//  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
原文地址:https://www.cnblogs.com/gaoxiaoniu/p/5308069.html