美文网首页
UIView 添加BackViewInit

UIView 添加BackViewInit

作者: 风___________ | 来源:发表于2018-12-25 15:41 被阅读7次

    .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
    

    相关文章

      网友评论

          本文标题:UIView 添加BackViewInit

          本文链接:https://www.haomeiwen.com/subject/pyyflqtx.html