// // DetailFeatureCell.m // FirstLink // // Created by jack on 15/8/25. // Copyright (c) 2015年 FirstLink. All rights reserved. // #import "DetailFeatureCell.h" @interface DetailFeatureCell () @property (nonatomic, strong) UIImageView *contentBg; @end @implementation DetailFeatureCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self addAllSubviews]; self.selectionStyle = UITableViewCellSelectionStyleNone; } return self; } - (void)addAllSubviews{ [self.contentView addSubview:self.contentBg]; [self.contentBg mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.insets(UIEdgeInsetsMake(15, 10, 15, 10)); }]; UIView *area0 = [[UIView alloc]init]; UIView *area1 = [[UIView alloc]init]; UIView *area2 = [[UIView alloc]init]; UIView *area3 = [[UIView alloc]init]; [self.contentBg addSubview:area0]; [self.contentBg addSubview:area1]; [self.contentBg addSubview:area2]; [self.contentBg addSubview:area3]; [area0 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.equalTo(self.contentBg); make.right.equalTo(self.contentBg.mas_centerX); make.bottom.equalTo(self.contentBg.mas_centerY); }]; [area1 mas_makeConstraints:^(MASConstraintMaker *make) { make.right.top.equalTo(self.contentBg); make.left.equalTo(self.contentBg.mas_centerX); make.bottom.equalTo(self.contentBg.mas_centerY); }]; [area2 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.bottom.equalTo(self.contentBg); make.right.equalTo(self.contentBg.mas_centerX); make.top.equalTo(self.contentBg.mas_centerY); }]; [area3 mas_makeConstraints:^(MASConstraintMaker *make) { make.right.bottom.equalTo(self.contentBg); make.left.equalTo(self.contentBg.mas_centerX); make.top.equalTo(self.contentBg.mas_centerY); }]; [self configArea:area0 withTitle:@"正品直购" subTitle:@"海外官网直购,更保真" imgName:@"zhengBg" isUp:YES isLeft:YES]; [self configArea:area1 withTitle:@"一键海淘" subTitle:@"一键跟单购买,更省心" imgName:@"taoBg" isUp:YES isLeft:NO]; [self configArea:area2 withTitle:@"实时低价" subTitle:@"同步实时价格,更低价" imgName:@"diBg" isUp:NO isLeft:YES]; [self configArea:area3 withTitle:@"全场包邮" subTitle:@"全场邮费补贴,更任性" imgName:@"baoBg" isUp:NO isLeft:NO]; } - (void)configArea:(UIView *)area withTitle:(NSString *)title subTitle:(NSString *)subTitle imgName:(NSString *)imgName isUp:(BOOL)isUp isLeft:(BOOL)isLeft{ UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:imgName]]; UILabel *titleLabel = ({ UILabel *label = [[UILabel alloc]init]; label.text = title; label.font = [UIFont systemFontOfSize:13]; label.textColor = UIColorFromRGB(0x333333); label; }); UILabel *subTitleLabel = ({ UILabel *label = [[UILabel alloc]init]; label.text = subTitle; label.font = [UIFont systemFontOfSize:10]; label.textColor = UIColorFromRGB(0x999999); label; }); [area addSubview:imageView]; [area addSubview:titleLabel]; [area addSubview:subTitleLabel]; CGFloat iphone6Move = 0; if (CGRectGetWidth([UIScreen mainScreen].bounds) > 320) iphone6Move = 10; if (isLeft) { // 在左边 [imageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(area).offset(5 + iphone6Move); if (isUp) { make.bottom.equalTo(area).offset(- 7.5); }else{ make.top.equalTo(area).offset(7.5); } }]; [subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.baseline.equalTo(imageView.mas_bottom); make.left.equalTo(titleLabel); }]; }else{ CGFloat bottomOff = - 12.5; if (isUp) bottomOff = - 5.5; [subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(area).offset(bottomOff); make.right.equalTo(area).offset(- 5 - iphone6Move); }]; [imageView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(subTitleLabel.mas_left).offset(- 10); make.bottom.equalTo(subTitleLabel.mas_baseline); }]; } [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(imageView.mas_right).offset(10); make.top.equalTo(imageView).offset(3); }]; } - (UIImageView *)contentBg{ if (_contentBg == nil) { UIImage *sizedImg = [[UIImage imageNamed:@"detailLineBg"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10) resizingMode:UIImageResizingModeTile]; _contentBg = [[UIImageView alloc]initWithImage:sizedImg]; } return _contentBg; } @end