GromoreDemoAdHandleCell.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // ABUDemoAdHandleCell.m
  3. // ABUDemo
  4. //
  5. // Created by heyinyin on 2021/12/15.
  6. // Copyright © 2021 bytedance. All rights reserved.
  7. //
  8. #import "GromoreDemoAdHandleCell.h"
  9. @interface GromoreDemoAdHandleCell ()
  10. // 广告加载流程
  11. @property (nonatomic, strong) UIView *adView;
  12. @property (nonatomic, strong) UIButton *adLoadButton;
  13. @property (nonatomic, strong) UIButton *adShowButton;
  14. @property (nonatomic, strong) UISwitch *showAdAfterAdLoad;
  15. @property (nonatomic, strong) UISwitch *showConsoleWhenAdLoad;
  16. @end
  17. @implementation GromoreDemoAdHandleCell
  18. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  19. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  20. [self initView];
  21. }
  22. self.selectionStyle = UITableViewCellSelectionStyleNone;
  23. return self;
  24. }
  25. - (void)initView {
  26. CGFloat x = 10;
  27. CGFloat y = 10;
  28. CGFloat width = (CGRectGetWidth([UIScreen mainScreen].bounds) - x * 3) / 2;
  29. CGFloat height = 40;
  30. _adLoadButton = [[UIButton alloc] initWithFrame:CGRectMake(x, y, width, height)];
  31. _adShowButton = [[UIButton alloc] initWithFrame:CGRectMake(x + width + 10 , y, width, height)];
  32. _adLoadButton.backgroundColor = RQ_MAIN_BACKGROUNDCOLOR;
  33. _adShowButton.backgroundColor = RQ_MAIN_BACKGROUNDCOLOR;
  34. _adLoadButton.clipsToBounds = YES;
  35. _adShowButton.clipsToBounds = YES;
  36. _adLoadButton.layer.cornerRadius = 5;
  37. _adShowButton.layer.cornerRadius = 5;
  38. [_adLoadButton setTitle:@"加载广告" forState:UIControlStateNormal];
  39. [_adShowButton setTitle:@"展示广告" forState:UIControlStateNormal];
  40. [_adLoadButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  41. [_adShowButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  42. [_adLoadButton addTarget:self action:@selector(loadAd) forControlEvents:UIControlEventTouchUpInside];
  43. [_adShowButton addTarget:self action:@selector(showAd) forControlEvents:UIControlEventTouchUpInside];
  44. [_adLoadButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
  45. [_adShowButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
  46. _showAdAfterAdLoad = [[UISwitch alloc] initWithFrame:CGRectMake(x, CGRectGetMaxY(_adLoadButton.frame) + 3, 30, 30)];
  47. [_showAdAfterAdLoad addTarget:self action:@selector(showAdWhenAdLoadChanged) forControlEvents:UIControlEventTouchUpInside];
  48. _showAdAfterAdLoad.tintColor = RQ_MAIN_COLOR;
  49. _showAdAfterAdLoad.transform = CGAffineTransformMakeScale(0.75, 0.75);
  50. _showAdAfterAdLoad.on = NO;
  51. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_showAdAfterAdLoad.frame) + 5, CGRectGetMaxY(_adLoadButton.frame) + 3, 310, 30)];
  52. label.textColor = RQ_MAIN_COLOR;
  53. label.font = RQRegularFont(13);
  54. label.text = @"加载成功后直接展示广告(仅设定除banner&native)";
  55. label.alpha = 0.7;
  56. // _showConsoleWhenAdLoad = [[UISwitch alloc] initWithFrame:CGRectMake(x, CGRectGetMaxY(_showAdAfterAdLoad.frame) + 3, 30, 30)];
  57. // [_showConsoleWhenAdLoad addTarget:self action:@selector(showConsoleChanged) forControlEvents:UIControlEventTouchUpInside];
  58. // _showConsoleWhenAdLoad.tintColor = GROMORE_338AFF_Color;
  59. // _showConsoleWhenAdLoad.transform = CGAffineTransformMakeScale(0.75, 0.75);
  60. // _showConsoleWhenAdLoad.on = NO;
  61. // UILabel *consoleLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_showConsoleWhenAdLoad.frame) + 5, CGRectGetMaxY(_showAdAfterAdLoad.frame) + 3, 310, 30)];
  62. // consoleLabel.textColor = RQ_MAIN_COLOR;
  63. // consoleLabel.font = RQRegularFont(13);
  64. // consoleLabel.text = @"控制台内容实时展示";
  65. // consoleLabel.alpha = 0.7;
  66. [self.contentView addSubview:_adLoadButton];
  67. [self.contentView addSubview:_adShowButton];
  68. [self.contentView addSubview:_showAdAfterAdLoad];
  69. // [self.contentView addSubview:_showConsoleWhenAdLoad];
  70. [self.contentView addSubview:label];
  71. // [self.contentView addSubview:consoleLabel];
  72. }
  73. - (void)showConsoleChanged {
  74. if ([self.delegate respondsToSelector:@selector(showConsole:)]) {
  75. [self.delegate showConsole:_showConsoleWhenAdLoad.on];
  76. }
  77. }
  78. - (BOOL)showAdAfterLoad {
  79. return _showAdAfterAdLoad.on;
  80. }
  81. - (void)showAdWhenAdLoadChanged {
  82. if ([self showAdAfterLoad]) {
  83. [self showButtonInteractive:NO];
  84. } else {
  85. [self showButtonInteractive:YES];
  86. }
  87. }
  88. - (void)showButtonInteractive:(BOOL)enable {
  89. if (enable) {
  90. [_adShowButton setUserInteractionEnabled:YES];
  91. _adShowButton.alpha = 1.0;
  92. } else {
  93. [_adShowButton setUserInteractionEnabled:NO];
  94. _adShowButton.alpha = 0.2;
  95. }
  96. }
  97. - (void)loadAd {
  98. if ([self.delegate respondsToSelector:@selector(loadButtonDidClick:)]) {
  99. [self.delegate loadButtonDidClick:self];
  100. }
  101. }
  102. - (void)showAd {
  103. if ([self.delegate respondsToSelector:@selector(showButtonDidClick:)]) {
  104. [self.delegate showButtonDidClick:self];
  105. }
  106. if ([self showAdAfterLoad]) {
  107. NSLog(@"已设定load后直接展示广告,展示按钮功能被禁用");
  108. }
  109. }
  110. - (void)changeAdStatus:(GromoreDemoAdStatus)adStatus {
  111. if (![self showAdAfterLoad]) {
  112. BOOL enable = YES;
  113. switch (adStatus) {
  114. case GromoreDemoAdStatusLoading:
  115. enable = NO;
  116. break;
  117. case GromoreDemoAdStatusLoadFailed:
  118. enable = NO;
  119. break;
  120. default:
  121. break;
  122. }
  123. [self showButtonInteractive:enable];
  124. }
  125. }
  126. @end