开发中遇到各种字体样式 各种大小设置 代码繁琐 由于本人太懒 不想写那么麻烦代码,于是乎 小装了 一把。
上代码 wtm
OC
_label.font = [UIFont regular:15];
swift
label.font = .regular(15)
.h文件
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIFont (Y)
+ (UIFont*)medium:(CGFloat)font;
+ (UIFont*)bold:(CGFloat)font;
+ (UIFont*)regular:(CGFloat)font;
+ (UIFont*)font:(CGFloat)font;
@end
NS_ASSUME_NONNULL_END
///点m文件
#import "UIFont+Y.h"
@implementation UIFont (Y)
+ (UIFont*)medium:(CGFloat)font{
return [UIFont systemFontOfSize:font weight:(UIFontWeightMedium)];
}
+ (UIFont*)bold:(CGFloat)font{
return [UIFont systemFontOfSize:font weight:(UIFontWeightBold)];
}
+ (UIFont*)regular:(CGFloat)font{
return [UIFont systemFontOfSize:font weight:(UIFontWeightRegular)];
}
+ (UIFont*)font:(CGFloat)font{
return [UIFont systemFontOfSize:font];
}
@end
非常好用 ,妈耶