最近設(shè)計這邊跟我說,我用的下拉刷新字體太粗,需要換成PingFang SC,我用的MJ的下拉刷新控件,我找了一下,發(fā)現(xiàn)下拉可以刷新和最后更新時間都用的同一個方法 + (instancetype)mj_label;

mj_label.png

實現(xiàn).png
本來還想直接改了這個方法的,但是發(fā)現(xiàn)自己是pod進來的,所以就放棄更改的想法了,那么最好的方法就是直接用runtime交換這個UILabel的分類方法。話不多說直接上代碼~
#import "RefreshHeader.h"
#import <objc/runtime.h>
#import <MJRefresh/MJRefreshComponent.h>
@implementation UILabel (WRRefresh)
+ (void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
SEL selector = @selector(mj_label);
NSString *newSelectorStr = [NSString stringWithFormat:@"wr_%@",NSStringFromSelector(selector)];
// 通過 class_getClassMethod 獲取類方法 (UILabel的分類)
Method originalMethod = class_getClassMethod([UILabel class], selector);
Method newMethod = class_getClassMethod(self, NSSelectorFromString(newSelectorStr));
method_exchangeImplementations(originalMethod, newMethod);
});
}
+ (instancetype)wr_mj_label
{
UILabel *label = [self wr_mj_label];
label.font = [UIFont fontWithName:@"PingFang SC" size:14];
return label;
}
@end
強烈推薦:超簡單!??! iOS設(shè)置狀態(tài)欄、導(dǎo)航欄按鈕、標(biāo)題、顏色、透明度,偏移等
https://github.com/wangrui460/WRNavigationBar
https://github.com/wangrui460/WRNavigationBar_swift
歡迎關(guān)注我的微博:wangrui460