123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- //
- // FKProActivityCell.m
- // FirstLink
- //
- // Created by jack on 16/8/13.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKProActivityCell.h"
- #import "FKProDetailViewModel.h"
- #import <BBCyclingLabel.h>
- @interface FKProActivityCell ()
- @property (nonatomic, strong) UILabel *tagLabel;
- @property (nonatomic, strong) UILabel *checkLabel;
- @property (nonatomic, strong) UIImageView *rightArrow;
- @property (nonatomic, strong) UIView *topLine;
- @property (nonatomic, strong) BBCyclingLabel *detailLabel;
- @property (nonatomic, strong) NSString *discountRule;
- @property (nonatomic, strong) NSTimer *timer;
- @property (nonatomic, strong) NSArray *array;
- @property (nonatomic, assign) NSInteger index;
- @end
- @implementation FKProActivityCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
-
- [self addAllSubviews];
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.contentView.backgroundColor = [UIColor whiteColor];
- }
- return self;
- }
- - (void)dealloc {
- [self.timer invalidate];
- self.timer = nil;
- }
- - (void)addAllSubviews{
-
- [self.contentView addSubview:self.tagLabel];
- [self.contentView addSubview:self.detailLabel];
- [self.contentView addSubview:self.checkLabel];
- [self.contentView addSubview:self.rightArrow];
- [self.contentView addSubview:self.topLine];
-
- [self.tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(15);
- make.centerY.equalTo(self.contentView);
- make.size.mas_equalTo(CGSizeMake(25, 14));
- }];
-
- [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.tagLabel.mas_right).offset(8);
- make.right.equalTo(self.contentView).offset(-15);
- make.centerY.equalTo(self.contentView);
- make.height.mas_equalTo(36);
- }];
-
- [self.rightArrow mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentView).offset(- 15);
- make.centerY.equalTo(self.contentView);
- }];
-
- [self.checkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.rightArrow.mas_left).offset(- 7);
- make.centerY.equalTo(self.contentView);
- }];
-
- [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(15);
- make.top.right.equalTo(self.contentView);
- make.height.mas_equalTo(0.5);
- }];
- }
- - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{
- if ([viewModel isKindOfClass:[FKProDetailViewModel class]]) {
- self.rightArrow.hidden = YES;
- self.checkLabel.hidden = YES;
- self.topLine.hidden = NO;
-
- if (indexPath.row == 0) self.topLine.hidden = YES;
-
- FKProDetailViewModel *detailModel = (FKProDetailViewModel *)viewModel;
- FKPromotionActivityItem *item = [detailModel activityItemAtIndex:indexPath.row];
- if ([FLStringHelper isValidString:item.targetUrl]) {
- self.rightArrow.hidden = NO;
- self.checkLabel.hidden = NO;
-
- self.checkLabel.text = @"查看活动";
- if ([item isActivityItem]) {
- self.checkLabel.text = @"领取优惠";
- }
-
- [self.detailLabel mas_updateConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentView).offset(-96);
- }];
- } else {
- [self.detailLabel mas_updateConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentView).offset(-15);
- }];
- }
-
- if (item) {
- if (![self.discountRule isEqualToString:item.discountRule]) {
- self.discountRule = item.discountRule;
- [self scrollUpDicountRule];
- }
- }
- }
- }
- - (void)scrollUpDicountRule {
- [self.timer invalidate]; self.timer = nil;
-
- NSArray *array = [self.discountRule componentsSeparatedByString:@" "];
- if (array.count > 0) {
- [self.detailLabel setText:array.firstObject animated:NO];
-
- if (array.count > 1) {
- self.index = 0;
- self.array = array;
- self.timer = [NSTimer scheduledTimerWithTimeInterval:3
- target:self
- selector:@selector(scrollUpDicountRuleCallback)
- userInfo:nil
- repeats:YES];
- }
- } else {
- [self.detailLabel setText:nil animated:YES];
- }
- }
- - (void)scrollUpDicountRuleCallback {
- if (self.array.count > 0) {
- self.index = (self.index + 1);
-
- [self.detailLabel setText:self.array[self.index % self.array.count] animated:YES];
- }
- }
- + (CGFloat)cellHeight{
- return 44.0f;
- }
- #pragma mark - property
- - (UILabel *)tagLabel {
- if (_tagLabel == nil) {
- _tagLabel = [[UILabel alloc]init];
- _tagLabel.textColor = [UIColor whiteColor];
- _tagLabel.backgroundColor = UIColorFromRGB(0xff6362);
- _tagLabel.font = [UIFont systemFontOfSize:10];
- _tagLabel.layer.cornerRadius = 3;
- _tagLabel.layer.masksToBounds = YES;
- _tagLabel.textAlignment = NSTextAlignmentCenter;
- _tagLabel.text = @"活动";
- }
- return _tagLabel;
- }
- - (BBCyclingLabel *)detailLabel {
- if (_detailLabel == nil) {
- _detailLabel = [[BBCyclingLabel alloc] initWithFrame:CGRectMake(0, 0, 320, 36)];
- _detailLabel.font = [UIFont systemFontOfSize:14];
- _detailLabel.textColor = UIColorFromRGB(0x666666);
- _detailLabel.transitionDuration = 0.8;
- _detailLabel.transitionEffect = BBCyclingLabelTransitionEffectScrollUp;
- _detailLabel.clipsToBounds = YES;
- }
- return _detailLabel;
- }
- - (UILabel *)checkLabel {
- if (_checkLabel == nil) {
- _checkLabel = [[UILabel alloc]init];
- _checkLabel.textColor = UIColorFromRGB(0x999999);
- _checkLabel.font = [UIFont systemFontOfSize:13];
- _checkLabel.text = @"查看活动";
- }
- return _checkLabel;
- }
- - (UIImageView *)rightArrow{
- if (_rightArrow == nil) {
- _rightArrow = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"more_right_arrow"]];
- }
- return _rightArrow;
- }
- - (UIView *)topLine{
- if (_topLine == nil) {
- _topLine = [[UIView alloc]init];
- _topLine.backgroundColor = UIColorFromRGB(0xe5e5e5);
- }
- return _topLine;
- }
- @end
|