dMethod2);
? ? ? ? }
? ? ? ? if (didAddMethod3) {
? ? ? ? ? ? class_replaceMethod(class,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? swizzledSelector3,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? method_getImplementation(originalMethod3),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? method_getTypeEncoding(originalMethod3));
? ? ? ? }else {
? ? ? ? ? ? method_exchangeImplementations(originalMethod3, swizzledMethod3);
? ? ? ? }
? ? });
? ?
}
/**
?*在这些方法中将你的字体名字换进去
?*/
- (instancetype)YHBaseInit
{
? ? id __self = [self YHBaseInit];
? ? UIFont * font = [UIFont fontWithName:@"这里输入你的字体名字" size:self.font.pointSize];
? ? if (font) {
? ? ? ? self.font=font;
? ? }
? ? return __self;
}
?
-(instancetype)YHBaseInitWithFrame:(CGRect)rect{
? ? id __self = [self YHBaseInitWithFrame:rect];
? ? UIFont * font = [UIFont fontWithName:@"这里输入你的字体名字" size:self.font.pointSize];
? ? if (font) {
? ? ? ? self.font=font;
? ? }
? ? return __self;
}
-(void)YHBaseAwakeFromNib{
? ? [self YHBaseAwakeFromNib];
? ? UIFont * font = [UIFont fontWithName:@"这里输入你的字体名字" size:self.font.pointSize];
? ? if (font) {
? ? ? ? self.font=font;
? ? }
? ?
}
?
@end
在上面的方法中写入我们想要UILabel默认显示的字体,我们分别从init,initWithFrame和nib文件创建一个UILabel添加到视图上,不做任何其他的操作:
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(20, 100, 280, 30)];
? ? label.text = @"你是从initWithFrame来的label";
? ? UILabel * label2 = [[UILabel alloc]init];
? ? label2.frame= CGRectMake(20, 200, 280, 30);
? ? label2.text = @"你是从init来的label";
? ? [self.view addSubview:label];
? ? [self.view addSubview:label2];

?
运行效果如下,可以看出,字体全部换掉了:
