最近設(shè)計(jì)這邊跟我說(shuō),我用的下拉刷新字體太粗灭翔,需要換成PingFang SC魏烫,我用的MJ的下拉刷新控件,我找了一下,發(fā)現(xiàn)下拉可以刷新和最后更新時(shí)間都用的同一個(gè)方法 + (instancetype)mj_label;
mj_label.png
實(shí)現(xiàn).png
本來(lái)還想直接改了這個(gè)方法的哄褒,但是發(fā)現(xiàn)自己是pod進(jìn)來(lái)的稀蟋,所以就放棄更改的想法了,那么最好的方法就是直接用runtime交換這個(gè)UILabel的分類(lèi)方法呐赡。話不多說(shuō)直接上代碼~
#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)];
// 通過(guò) class_getClassMethod 獲取類(lèi)方法 (UILabel的分類(lèi))
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
強(qiáng)烈推薦:超簡(jiǎn)單M丝汀!罚舱! iOS設(shè)置狀態(tài)欄井辜、導(dǎo)航欄按鈕、標(biāo)題管闷、顏色粥脚、透明度,偏移等
https://github.com/wangrui460/WRNavigationBar
https://github.com/wangrui460/WRNavigationBar_swift
歡迎關(guān)注我的微博:wangrui460