标签:
- (BOOL)ktj_changeColorWithAnimation:(BOOL)animation duration:(CGFloat)duration { if ([KTJNightVersion shouldChangeColor:self]) { KTJNightVersionStyle style = [KTJNightVersion currentStyle]; UIColor *backgroundColor; switch (style) { case KTJNightVersionStyleNormal: backgroundColor = self.ktj_normalBackgroudColor; break; case KTJNightVersionStyleNight: backgroundColor = self.ktj_nightBackgroudColor; break; default: backgroundColor = self.backgroundColor; break; } JGWeak(self); void (^changeColor)(void) = ^(void) { [weakself ktjhook_setBackgroundColor:backgroundColor]; }; if (animation) { [UIView animateWithDuration:duration animations:changeColor]; } else { changeColor(); } return YES; } else { return NO; } }
- (BOOL)ktj_changeColorWithAnimation:(BOOL)animation duration:(CGFloat)duration { if ([super respondsToSelector:@selector(ktj_changeColorWithAnimation:duration:)]) { if ([super ktj_changeColorWithAnimation:animation duration:duration]) { KTJNightVersionStyle style = [KTJNightVersion currentStyle]; UIColor *separatorColor; switch (style) { case KTJNightVersionStyleNormal: separatorColor = self.ktj_normalSeparatorColor; break; case KTJNightVersionStyleNight: separatorColor = self.ktj_nightSeparatorColor; break; default: separatorColor = self.separatorColor; break; } JGWeak(self); void (^changeColor)(void) = ^(void) { [weakself ktjhook_setSeparatorColor:separatorColor]; }; if (animation) { [UIView animateWithDuration:duration animations:changeColor]; } else { changeColor(); } return YES; } } return NO; }
+ (void)load { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ KTJChangeIMP(@selector(setSeparatorColor:), @selector(ktjhook_setSeparatorColor:)); }); } - (void)ktjhook_setSeparatorColor:(UIColor *)separatorColor { self.ktj_normalSeparatorColor = separatorColor; [self ktjhook_setSeparatorColor:separatorColor]; } - (void)setKtj_nightSeparatorColor:(UIColor *)ktj_nightSeparatorColor { if ([KTJNightVersion currentStyle] == KTJNightVersionStyleNight) { [self ktjhook_setSeparatorColor:ktj_nightSeparatorColor]; } objc_setAssociatedObject(self, @selector(ktj_nightSeparatorColor), ktj_nightSeparatorColor, OBJC_ASSOCIATION_RETAIN); } - (UIColor *)ktj_nightSeparatorColor { return objc_getAssociatedObject(self, @selector(ktj_nightSeparatorColor))?:self.separatorColor; } - (void)setKtj_normalSeparatorColor:(UIColor *)ktj_normalSeparatorColor { if ([KTJNightVersion currentStyle] == KTJNightVersionStyleNormal) { [self ktjhook_setSeparatorColor:ktj_normalSeparatorColor]; } objc_getAssociatedObject(self, @selector(ktj_normalSeparatorColor))?:self.separatorColor; } - (void)ktj_saveNormalSeparatorColor:(UIColor *)separatorColor { objc_setAssociatedObject(self, @selector(ktj_normalSeparatorColor), separatorColor, OBJC_ASSOCIATION_RETAIN); }
标签:
原文地址:http://www.cnblogs.com/madordie/p/4716396.html