// // SubmitAddNewAddressCell.m // FirstLink // // Created by jack on 15/6/18. // Copyright (c) 2015年 FirstLink. All rights reserved. // #import "SubmitAddNewCell.h" @interface SubmitAddNewCell () @property (nonatomic, strong) UIImageView *iconView; @property (nonatomic, strong) UILabel *titleLabel; @property (nonatomic, strong) UIImageView *rightArrow; @property (nonatomic, strong) UIView *bottomLine; @end @implementation SubmitAddNewCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { self.selectionStyle = UITableViewCellSelectionStyleNone; [self addAllSubviews]; self.bottomColorLine.hidden = self.topColorLine.hidden = YES; } return self; } - (void)addAllSubviews { [self.contentView addSubview:self.iconView]; [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(15); make.centerY.equalTo(self.contentView).offset(-2); make.size.mas_equalTo(CGSizeMake(30, 30)); }]; [self.contentView addSubview:self.rightArrow]; [self.rightArrow mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.contentView).offset(-15); make.centerY.equalTo(self.contentView); }]; [self.contentView addSubview:self.titleLabel]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.iconView.mas_right).offset(15); make.right.equalTo(self.contentView).offset(-30); make.centerY.equalTo(self.contentView); }]; [self.contentView addSubview:self.bottomLine]; [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(15); make.height.equalTo(@0.5); make.bottom.right.equalTo(self.contentView); }]; [self.contentView addSubview:self.topColorLine]; [self.topColorLine mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.right.equalTo(self.contentView); make.height.mas_equalTo(@2); }]; [self.contentView addSubview:self.bottomColorLine]; [self.bottomColorLine mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(14); make.bottom.equalTo(self.contentView); make.right.equalTo(self.contentView).offset(14); make.height.mas_equalTo(@2); }]; } #pragma mark - Function - (void)fk_configWithViewModel:(FKSubmitOrderViewModel *)viewModel indexPath:(NSIndexPath *)indexPath{ kSubmitProCellType type = [viewModel cellTypeForIndexPath:indexPath]; if (type == kSubmitProCellTypeAddAddress){ [self configCellWith:@"AddNewAddressIcon" title:[SubmitAddNewCell addNewAddressTipString]]; self.topColorLine.hidden = NO; self.bottomColorLine.hidden = ([viewModel.needIdCardType isEqualToString:@"3"] ? YES : NO); }else if (type == kSubmitProCellTypeAddIDCard){ [self configCellWith:@"AddNewIdCardIcon" title:[SubmitAddNewCell addNewIDCardTipString]]; self.topColorLine.hidden = ([viewModel.needIdCardType isEqualToString:@"3"] ? YES : NO); self.bottomColorLine.hidden = NO; if ([viewModel.needIdCardType isEqualToString:@"3"]) { [self.bottomColorLine mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView); make.bottom.equalTo(self.contentView); make.right.equalTo(self.contentView); make.height.mas_equalTo(@2); }]; } else { [self.bottomColorLine mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(14); make.bottom.equalTo(self.contentView); make.right.equalTo(self.contentView).offset(14); make.height.mas_equalTo(@2); }]; } } } - (void)configCellWith:(NSString *)iconName title:(NSAttributedString *)attributedTitle { self.iconView.image = [UIImage imageNamed:iconName]; self.titleLabel.attributedText = attributedTitle; } + (NSAttributedString *)addNewAddressTipString { NSString *string = @"新增收货地址"; NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:string]; [attributeString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, string.length)]; [attributeString addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x333333) range:NSMakeRange(0, string.length)]; return attributeString; } + (NSAttributedString *)addNewIDCardTipString { NSString *string = @"新增身份信息(必填)"; NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:string]; [attributeString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, 6)]; [attributeString addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x333333) range:NSMakeRange(0, 6)]; [attributeString addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xff6362) range:NSMakeRange(6, 4)]; return attributeString; } #pragma mark - Property - (UIImageView *)iconView { if (!_iconView) { _iconView = [UIImageView new]; } return _iconView; } - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [UILabel new]; _titleLabel.font = [UIFont systemFontOfSize:14]; _titleLabel.textColor = UIColorFromRGB(0x999999); // _titleLabel.text = @"新增收货地址"; } return _titleLabel; } - (UIImageView *)rightArrow { if (!_rightArrow) { _rightArrow = [UIImageView new]; _rightArrow.image = [UIImage imageNamed:@"Cell_More_Icon"]; } return _rightArrow; } - (UIView *)bottomLine { if (!_bottomLine) { _bottomLine = [[UIView alloc]init]; _bottomLine.backgroundColor = UIColorFromRGB(0xe5e5e5); } return _bottomLine; } - (UIImageView *)topColorLine{ if (_topColorLine == nil) { UIImage *resizeImg = [[UIImage imageNamed:@"submit_colorLine"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 4) resizingMode:UIImageResizingModeTile]; _topColorLine = [[UIImageView alloc]initWithImage:resizeImg]; } return _topColorLine; } - (UIImageView *)bottomColorLine{ if (_bottomColorLine == nil) { UIImage *resizeImg = [[UIImage imageNamed:@"submit_colorLine"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 4) resizingMode:UIImageResizingModeTile]; _bottomColorLine = [[UIImageView alloc]initWithImage:resizeImg]; } return _bottomColorLine; } @end