12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- //
- // XHLaunchAdButton+RQExtension.m
- // jiaPei
- //
- // Created by 张嵘 on 2020/4/9.
- // Copyright © 2020 JCZ. All rights reserved.
- //
- #import "XHLaunchAdButton+RQExtension.h"
- #import <objc/runtime.h>
- /** Progress颜色 */
- #define RoundProgressColor [UIColor whiteColor]
- /** 背景色 */
- #define BackgroundColor [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4]
- /** 字体颜色 */
- #define FontColor [UIColor whiteColor]
- #define SkipTitle @"跳过"
- /** 倒计时单位 */
- #define DurationUnit @""
- @interface XHLaunchAdButton (RQExtennsion)
- @property(nonatomic,strong)UILabel *timeLab;
- @end
- @implementation XHLaunchAdButton (RQExtension)
- + (void)load {
- // 方法交换,为的是当XHLaunchAdButton调用setTitleWithSkipType时候,调用的是我们的my_setTitleWithSkipType方法
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- Class class = [self class];
- SEL originalSelector = @selector(setTitleWithSkipType:duration:);
- SEL swizzledSelector = @selector(my_setTitleWithSkipType:duration:);
- Method originalMethod = class_getInstanceMethod(class, originalSelector);
- Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
- BOOL success = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
- if (success) {
- class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
- } else {
- method_exchangeImplementations(originalMethod, swizzledMethod);
- }
- });
- }
- - (void)my_setTitleWithSkipType:(SkipType)skipType duration:(NSInteger)duration{
- [self my_setTitleWithSkipType:skipType duration:duration]; // 由于方法交换,实际上调用的是XHLaunchAdButton的setTitleWithSkipType
- /// 禁止跳过
- self.userInteractionEnabled = NO;
- switch (skipType) {
- case SkipTypeNone:{
- self.hidden = YES;
- }
- break;
- case SkipTypeTime:{
- self.hidden = NO;
- self.timeLab.text = [NSString stringWithFormat:@"%ld %@",duration,DurationUnit];
- }
- break;
- case SkipTypeText:{
- self.hidden = NO;
- self.timeLab.text = SkipTitle;
- }
- break;
- case SkipTypeTimeText:{
- self.hidden = NO;
- self.timeLab.text = [NSString stringWithFormat:@"%ld %@",duration,SkipTitle];
- }
- break;
- case SkipTypeRoundTime:{
- self.hidden = NO;
- self.timeLab.text = [NSString stringWithFormat:@"%ld %@",duration,DurationUnit];
- }
- break;
- case SkipTypeRoundText:{
- self.hidden = NO;
- self.timeLab.text = SkipTitle;
- }
- break;
- case SkipTypeRoundProgressTime:{
- self.hidden = NO;
- self.timeLab.text = [NSString stringWithFormat:@"%ld %@",duration,DurationUnit];
- }
- break;
- case SkipTypeRoundProgressText:{
- self.hidden = NO;
- self.timeLab.text = SkipTitle;
- }
- break;
- default:
- break;
- }
- }
- @end
|