1. 先设置自定义的字体
将字体文件拖到工程目录中,并增添加到Bundle中。这里以阿里巴巴普惠体
为例。
2. 在info.plist中增加字体
3. 添加字体类
右键创建新文件->选择OC文件
- File: 自己定义一个文件名
- File Type:Category
- Class:UIFont
4. 在.h文件中添加
+(UIFont *)systemFontOfSize:(CGFloat)fontSize;
//
// UIFont+Custom.h
//
// Created by 55 on 2019/11/7.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIFont (UIFontCustom)
+(UIFont *)systemFontOfSize:(CGFloat)fontSize;
@end
NS_ASSUME_NONNULL_END
5. 在.m中实现systemFontOfSize方法
//
// UIFont+Custom.m
//
// Created by 55 on 2019/11/7.
//
#import "UIFont+Custom.h"
@implementation UIFont (UIFontCustom)
+(UIFont *)systemFontOfSize:(CGFloat)fontSize
{
return [UIFont fontWithName:@"AlibabaPuHuiTi-Medium" size:fontSize];
}
@end