交换方法

来源:互联网 发布:钓鱼软件生成器下载 编辑:程序博客网 时间:2024/04/30 10:09
#import "UIImage+AddImageFunc.h"#import <objc/runtime.h>@implementation UIImage (AddImageFunc)+ (void)load {    Method methodOfOrigin = class_getClassMethod(self, @selector(imageNamed:));    Method methodOfCurrent= class_getClassMethod(self, @selector(custom_imageNamed:));    //交换两个方法    method_exchangeImplementations(methodOfOrigin, methodOfCurrent);}/* * 外界主动调用 imageNamed: 的时候,相当于调用了custom_imageNamed:这个方法 * **/+ (UIImage *)custom_imageNamed:(NSString *)name {    if (name.length == 0) {        name = @"1";    }    /*     *  1.当 主动调用 [self custom_imageNamed:name]        2.因为已经交换了 所以相当于调用[self imageNamed:name];     **/    UIImage * image = [self custom_imageNamed:name];    return image;    return nil;}@end
0 0
原创粉丝点击