// // FKGroupStepCell.m // FirstLink // // Created by jack on 15/10/7. // Copyright © 2015年 FirstLink. All rights reserved. // #import "FKGroupStepCell.h" #define kNumLabelTagBase 1000 #define kStepLabelTagBase 2000 #define kAreaTagBase 500 #define VIP_PROTOCOL_URL ([NSString stringWithFormat:@"%@/link-site/mobile/fightGroups/explain.html", [[FKServerUtil sharedInstance] apiServer]]) @interface FKGroupStepCell () @property (nonatomic, strong) UILabel *leftLabel; @property (nonatomic, strong) UILabel *rightLabel; @property (nonatomic, strong) UIImageView *rightArrow; @end @implementation FKGroupStepCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { self.selectionStyle = UITableViewCellSelectionStyleNone; [self addAllSubviews]; } return self; } + (NSString *)pushExplainUrl{ return VIP_PROTOCOL_URL; } - (void)addAllSubviews{ UIView *area1 = [[UIView alloc]init]; UIView *area2 = [[UIView alloc]init]; UIView *area3 = [[UIView alloc]init]; UIView *area4 = [[UIView alloc]init]; [self.contentView addSubview:self.leftLabel]; [self.contentView addSubview:self.rightLabel]; [self.contentView addSubview:self.rightArrow]; [self.contentView addSubview:area1]; [self.contentView addSubview:area2]; [self.contentView addSubview:area3]; [self.contentView addSubview:area4]; [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(10); make.top.equalTo(self.contentView).offset(10); }]; [self.rightArrow mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.leftLabel); make.right.equalTo(self.contentView).offset(-12); }]; [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.leftLabel); make.right.equalTo(self.rightArrow.mas_left).offset(-6); }]; [area1 mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.leftLabel.mas_bottom); make.left.bottom.equalTo(self.contentView); make.width.equalTo(self.contentView).multipliedBy(0.25); }]; [area2 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(area1.mas_right); make.top.bottom.equalTo(area1); make.width.equalTo(self.contentView).multipliedBy(0.25); }]; [area3 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(area2.mas_right); make.top.bottom.equalTo(area1); make.width.equalTo(self.contentView).multipliedBy(0.25); }]; [area4 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(area3.mas_right); make.top.bottom.equalTo(area1); make.right.equalTo(self.contentView); }]; [self configArea:area1 stepNum:kGroupStepSelect title:@"选择心仪\n的商品"]; [self configArea:area2 stepNum:kGroupStepPay title:@"支付开团\n或参团"]; [self configArea:area3 stepNum:kGroupStepInvite title:@"邀请好友\n参团支付"]; [self configArea:area4 stepNum:kGroupStepFinish title:@"达到人数\n团购成功"]; } - (void)configArea:(UIView *)area stepNum:(kGroupStep)step title:(NSString *)title{ area.tag = kAreaTagBase + step; UIImageView *circle = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"xuCircle"]]; UILabel *numLabel = [self createNumLabelWithText:[NSString stringWithFormat:@"%lu", ((unsigned long)step + 1)] tag:kNumLabelTagBase + step]; UILabel *titleLabel = [self createLabelWithTitle:title tag:kStepLabelTagBase + step]; [area addSubview:circle]; [area addSubview:numLabel]; [area addSubview:titleLabel]; // UI布局适配 CGFloat margin = 10; CGFloat titleMargin = 8; if (step != kGroupStepSelect && (IS_IPHONE_4 || IS_IPHONE_5)) margin = 5; if (IS_IPHONE_4 || IS_IPHONE_5) titleMargin = 4; [circle mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(area).offset(margin); make.centerY.equalTo(area); }]; [numLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.center.equalTo(circle); make.width.height.mas_equalTo(20); }]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(circle.mas_right).offset(titleMargin); make.centerY.equalTo(circle); }]; } - (UILabel *)createNumLabelWithText:(NSString *)text tag:(NSUInteger)tag{ UILabel *label = [[UILabel alloc]init]; label.textColor = UIColorFromRGB(0x666666); label.layer.cornerRadius = 10; label.layer.masksToBounds = YES; label.textAlignment = NSTextAlignmentCenter; label.font = [UIFont boldSystemFontOfSize:12]; label.tag = tag; label.text = text; return label; } - (UILabel *)createLabelWithTitle:(NSString *)title tag:(NSUInteger)tag{ UILabel *label = [[UILabel alloc]init]; label.text = title; label.tag = tag; label.font = [UIFont systemFontOfSize:11]; label.textColor = UIColorFromRGB(0x666666); label.numberOfLines = 0; return label; } - (void)setStep:(kGroupStep)step{ UIView *area = [self.contentView viewWithTag:kAreaTagBase + step]; UILabel *numLabel = (UILabel *)[area viewWithTag:kNumLabelTagBase + step]; UILabel *titleLabel = (UILabel *)[area viewWithTag:kStepLabelTagBase + step]; if (numLabel) { numLabel.backgroundColor = UIColorFromRGB(0x49d0bb); numLabel.textColor = [UIColor whiteColor]; } if (titleLabel){ titleLabel.textColor = UIColorFromRGB(0x49d0bb); } } - (UILabel *)leftLabel{ if (_leftLabel == nil) { _leftLabel = [[UILabel alloc]init]; _leftLabel.textColor = UIColorFromRGB(0x999999); _leftLabel.font = [UIFont systemFontOfSize:11]; _leftLabel.text = @"拼团玩法"; } return _leftLabel; } - (UILabel *)rightLabel{ if (_rightLabel == nil) { _rightLabel = [[UILabel alloc]init]; _rightLabel.textColor = UIColorFromRGB(0x333333); _rightLabel.font = [UIFont systemFontOfSize:12]; _rightLabel.text = @"活动详情"; } return _rightLabel; } - (UIImageView *)rightArrow{ if (_rightArrow == nil) { _rightArrow = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"groupRightArrow_small"]]; } return _rightArrow; } @end