Brak opisu

FKProActivityCell.m 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. //
  2. // FKProActivityCell.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/8/13.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKProActivityCell.h"
  9. #import "FKProDetailViewModel.h"
  10. #import <BBCyclingLabel.h>
  11. @interface FKProActivityCell ()
  12. @property (nonatomic, strong) UILabel *tagLabel;
  13. @property (nonatomic, strong) UILabel *checkLabel;
  14. @property (nonatomic, strong) UIImageView *rightArrow;
  15. @property (nonatomic, strong) UIView *topLine;
  16. @property (nonatomic, strong) BBCyclingLabel *detailLabel;
  17. @property (nonatomic, strong) NSString *discountRule;
  18. @property (nonatomic, strong) NSTimer *timer;
  19. @property (nonatomic, strong) NSArray *array;
  20. @property (nonatomic, assign) NSInteger index;
  21. @end
  22. @implementation FKProActivityCell
  23. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  24. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  25. [self addAllSubviews];
  26. self.selectionStyle = UITableViewCellSelectionStyleNone;
  27. self.contentView.backgroundColor = [UIColor whiteColor];
  28. }
  29. return self;
  30. }
  31. - (void)dealloc {
  32. [self.timer invalidate];
  33. self.timer = nil;
  34. }
  35. - (void)addAllSubviews{
  36. [self.contentView addSubview:self.tagLabel];
  37. [self.contentView addSubview:self.detailLabel];
  38. [self.contentView addSubview:self.checkLabel];
  39. [self.contentView addSubview:self.rightArrow];
  40. [self.contentView addSubview:self.topLine];
  41. [self.tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.equalTo(self.contentView).offset(15);
  43. make.centerY.equalTo(self.contentView);
  44. make.size.mas_equalTo(CGSizeMake(25, 14));
  45. }];
  46. [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.left.equalTo(self.tagLabel.mas_right).offset(8);
  48. make.right.equalTo(self.contentView).offset(-15);
  49. make.centerY.equalTo(self.contentView);
  50. make.height.mas_equalTo(36);
  51. }];
  52. [self.rightArrow mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.right.equalTo(self.contentView).offset(- 15);
  54. make.centerY.equalTo(self.contentView);
  55. }];
  56. [self.checkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.right.equalTo(self.rightArrow.mas_left).offset(- 7);
  58. make.centerY.equalTo(self.contentView);
  59. }];
  60. [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.left.equalTo(self.contentView).offset(15);
  62. make.top.right.equalTo(self.contentView);
  63. make.height.mas_equalTo(0.5);
  64. }];
  65. }
  66. - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{
  67. if ([viewModel isKindOfClass:[FKProDetailViewModel class]]) {
  68. self.rightArrow.hidden = YES;
  69. self.checkLabel.hidden = YES;
  70. self.topLine.hidden = NO;
  71. if (indexPath.row == 0) self.topLine.hidden = YES;
  72. FKProDetailViewModel *detailModel = (FKProDetailViewModel *)viewModel;
  73. FKPromotionActivityItem *item = [detailModel activityItemAtIndex:indexPath.row];
  74. if ([FLStringHelper isValidString:item.targetUrl]) {
  75. self.rightArrow.hidden = NO;
  76. self.checkLabel.hidden = NO;
  77. self.checkLabel.text = @"查看活动";
  78. if ([item isActivityItem]) {
  79. self.checkLabel.text = @"领取优惠";
  80. }
  81. [self.detailLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  82. make.right.equalTo(self.contentView).offset(-96);
  83. }];
  84. } else {
  85. [self.detailLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  86. make.right.equalTo(self.contentView).offset(-15);
  87. }];
  88. }
  89. if (item) {
  90. if (![self.discountRule isEqualToString:item.discountRule]) {
  91. self.discountRule = item.discountRule;
  92. [self scrollUpDicountRule];
  93. }
  94. }
  95. }
  96. }
  97. - (void)scrollUpDicountRule {
  98. [self.timer invalidate]; self.timer = nil;
  99. NSArray *array = [self.discountRule componentsSeparatedByString:@" "];
  100. if (array.count > 0) {
  101. [self.detailLabel setText:array.firstObject animated:NO];
  102. if (array.count > 1) {
  103. self.index = 0;
  104. self.array = array;
  105. self.timer = [NSTimer scheduledTimerWithTimeInterval:3
  106. target:self
  107. selector:@selector(scrollUpDicountRuleCallback)
  108. userInfo:nil
  109. repeats:YES];
  110. }
  111. } else {
  112. [self.detailLabel setText:nil animated:YES];
  113. }
  114. }
  115. - (void)scrollUpDicountRuleCallback {
  116. if (self.array.count > 0) {
  117. self.index = (self.index + 1);
  118. [self.detailLabel setText:self.array[self.index % self.array.count] animated:YES];
  119. }
  120. }
  121. + (CGFloat)cellHeight{
  122. return 44.0f;
  123. }
  124. #pragma mark - property
  125. - (UILabel *)tagLabel {
  126. if (_tagLabel == nil) {
  127. _tagLabel = [[UILabel alloc]init];
  128. _tagLabel.textColor = [UIColor whiteColor];
  129. _tagLabel.backgroundColor = UIColorFromRGB(0xff6362);
  130. _tagLabel.font = [UIFont systemFontOfSize:10];
  131. _tagLabel.layer.cornerRadius = 3;
  132. _tagLabel.layer.masksToBounds = YES;
  133. _tagLabel.textAlignment = NSTextAlignmentCenter;
  134. _tagLabel.text = @"活动";
  135. }
  136. return _tagLabel;
  137. }
  138. - (BBCyclingLabel *)detailLabel {
  139. if (_detailLabel == nil) {
  140. _detailLabel = [[BBCyclingLabel alloc] initWithFrame:CGRectMake(0, 0, 320, 36)];
  141. _detailLabel.font = [UIFont systemFontOfSize:14];
  142. _detailLabel.textColor = UIColorFromRGB(0x666666);
  143. _detailLabel.transitionDuration = 0.8;
  144. _detailLabel.transitionEffect = BBCyclingLabelTransitionEffectScrollUp;
  145. _detailLabel.clipsToBounds = YES;
  146. }
  147. return _detailLabel;
  148. }
  149. - (UILabel *)checkLabel {
  150. if (_checkLabel == nil) {
  151. _checkLabel = [[UILabel alloc]init];
  152. _checkLabel.textColor = UIColorFromRGB(0x999999);
  153. _checkLabel.font = [UIFont systemFontOfSize:13];
  154. _checkLabel.text = @"查看活动";
  155. }
  156. return _checkLabel;
  157. }
  158. - (UIImageView *)rightArrow{
  159. if (_rightArrow == nil) {
  160. _rightArrow = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"more_right_arrow"]];
  161. }
  162. return _rightArrow;
  163. }
  164. - (UIView *)topLine{
  165. if (_topLine == nil) {
  166. _topLine = [[UIView alloc]init];
  167. _topLine.backgroundColor = UIColorFromRGB(0xe5e5e5);
  168. }
  169. return _topLine;
  170. }
  171. @end