
本文共 2420 字,大约阅读时间需要 8 分钟。
UI������������
Objective-C Runtime������������������
������Runtime��������������������� ��������������������������� ������������
���Objective-C������������������ class_replaceMethod ���������������������������������������������������
class_replaceMethod ��������������������������������������������������������� class_addMethod ������������������������
������Objective-C������������������API������������������������������������method_exchangeImplementations���method_setImplementation
method_exchangeImplementations ������������������Method���������������
���UIImage������������������������������Runtime������������������
���UIImage������
������������
Objective-C������������
@implementation UIImage (Image)
@+(void)load
{ Method imageNamedMethod = class_getClassMethod(self, @selector(imageNamed:)); Method xmg_imageNamedMethod = class_getClassMethod(self, @selector(xmg_imageNamed:));
method_exchangeImplementations(imageNamedMethod, xmg_imageNamedMethod);Method method1 = class_getInstanceMethod(self, @selector(sayOne));Method method2 = class_getInstanceMethod(self, @selector(sayTwo));method_exchangeImplementations(method1, method2);
}
@+(UIImage *)xmg_imageNamed:(NSString *)name
{ UIImage *image = [UIImage xmg_imageNamed:name]; if (image) { NSLog(@"������������"); } else { NSLog(@"������������"); } return image; }
@-(void)sayOne
{ NSLog(@"One"); }
@-(void)sayTwo
{ NSLog(@"Two"); }
@end
���������������
[UIImage xmg_imageNamed:@"one.png"] // ���������������������
UI������������
���������������������
Method class_getInstanceMethod(Class cls SEL name)
Class
Class������Class���������������sel������ Selector������������Method������
Class_getInstanceMethod������������������������
������method_exchangeImplementations������������������������������������������
������������
������������������������
���������������������������������������������
load���initialize������������
load���������������������������������������������������������������������������������������������
���������load���������������������������������������������������������������������
initialize������������������������������������������������������������������������������������������������������������������������������������
������������load���������������������������������������������������������
���������
���load���������������������������������������������������������������������
������������������������������������������������
发表评论
最新留言
关于作者
