Skip to content

Instantly share code, notes, and snippets.

@maddiesch
Last active December 26, 2015 04:19
Show Gist options
  • Save maddiesch/7092414 to your computer and use it in GitHub Desktop.
Save maddiesch/7092414 to your computer and use it in GitHub Desktop.
Blog Post On Auto Layout
#import <objc/runtime.h>
NS_INLINE void xx_MethodSwizzle(Class c, SEL origSEL, SEL overrideSEL) {
Method origMethod = class_getInstanceMethod(c, origSEL);
Method overrideMethod = class_getInstanceMethod(c, overrideSEL);
if(class_addMethod(c, origSEL, method_getImplementation(overrideMethod), method_getTypeEncoding(overrideMethod))) {
class_replaceMethod(c, overrideSEL, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
} else {
method_exchangeImplementations(origMethod, overrideMethod);
}
}
@interface UITableView (AutoLayoutFixForRefreshIndicatorInTableView)
@end
@implementation UITableView (PCOKitAutoLayoutFixForRefreshIndicatorInTableView)
+ (void)load {
xx_MethodSwizzle(self, @selector(layoutSubviews), @selector(xx_autoLayoutLayoutSubviews));
}
- (void)xx_autoLayoutLayoutSubviews {
[self xx_autoLayoutLayoutSubviews]; // Call the original implementation
[super layoutSubviews];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment