.h
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIView (BackViewInit)
- (void)backViewInit;
@end
NS_ASSUME_NONNULL_END
.m
#import "UIView+BackViewInit.h"
#import <objc/runtime.h>
@implementation UIView (BackViewInit)
+ (void)load{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Method originalMethod = class_getInstanceMethod(self, @selector(initWithFrame:));
Method swizzledMethod = class_getInstanceMethod(self, @selector(jc_initWithFrame:));
method_exchangeImplementations(originalMethod, swizzledMethod);
});
}
- (instancetype)jc_initWithFrame:(CGRect)frame{
UIView *obj = [self jc_initWithFrame:frame];
[obj backViewInit];
return obj;
}
- (void)backViewInit{
}
@end
网友评论