在我们项目中有时候,需要用到这个强大的功能,特别是一些老项目,要是实现的地方多的话,你不可能一一去修改吧。那么这时,就是体现runtime强大的时候了,当然runtime还有很多功能,比如动态添加属性呀,添加方法等。

需求:我们需要将系统的这个类方法 [UIImage imageNamed:@"vip"]的实现变成我们自己自定义的。
首先需要弄个分类
#import"UIImage+Extension.h"
还需导入

接着要声明

然后再实现

接下来,你就可以去实现你刚刚声明的那个类方法了,任意施虐吧;
需要注意,如果你是对象方法的话需要将

换成

就可以了,快去试试吧,如果又错误的地方,还望指出来,见谅!
网友评论