Runtime

iOS运行时修改执行方法

920 发布: 2024/7/16 17:15 本文总阅读量

Runtime 动态修改执行方法

#import "TYTabPagerBarLayout+RKBarLayout.h"

@implementation TYTabPagerBarLayout (RKBarLayout)

+ (void)load {
    Method originalMethod = class_getInstanceMethod(self, @selector(setUnderLineFrameWithIndex:animated:));
    Method swizzledMethod = class_getInstanceMethod(self, @selector(rk_setUnderLineFrameWithIndex:animated:));
    method_exchangeImplementations(originalMethod, swizzledMethod);
    
    Method originalMethod2 = class_getInstanceMethod(self, @selector(setUnderLineFrameWithfromIndex:toIndex:progress:));
    Method swizzledMethod2 = class_getInstanceMethod(self, @selector(rk_setUnderLineFrameWithfromIndex:toIndex:progress:));
    method_exchangeImplementations(originalMethod2, swizzledMethod2);
}
- (void)rk_setUnderLineFrameWithIndex:(NSInteger)index animated:(BOOL)animated; {
    [self rk_setUnderLineFrameWithIndex:index animated:animated];
    [[NSNotificationCenter defaultCenter] postNotificationName:RKBarProgresChange object:nil];
}

- (void)rk_setUnderLineFrameWithfromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex progress:(CGFloat)progress;{
    [self rk_setUnderLineFrameWithfromIndex:fromIndex toIndex:toIndex progress:progress];
    [[NSNotificationCenter defaultCenter] postNotificationName:RKBarProgresChange object:nil];
}

@end