// // HSQCommunityCell.m // YouHuiProject // // Created by 小花 on 2018/5/16. // Copyright © 2018年 kuxuan. All rights reserved. // #import "HSQCommunityCell.h" #import "UIView+SDAutoLayout.h" #import "HSQCommunityDetailModel.h" #import "CCCopyLabel.h" @interface HSQCommunityCell () @property (nonatomic, strong) UIImageView *iconView; @property (nonatomic, strong) UIImageView *goodImgV; @property (nonatomic, strong) UILabel *userName; @property (nonatomic, strong)UILabel *goodNamelabel; @property (nonatomic, strong)UILabel *pricelabel; @property (nonatomic, strong)UILabel *commissionLabel; @property (nonatomic, strong)UILabel *vouchersLabel; @property (nonatomic, strong)UIButton *shareBtn; @property(nonatomic,strong)UILabel *backtiellabel; @property (nonatomic, strong) UILabel *timeLabel; @property (nonatomic, strong) CCCopyLabel *contentLabel; @property (nonatomic, strong) UIView *bottomLine; @property (nonatomic, strong) UIButton *oneTouchShareButton; @property(nonatomic,strong)UIView *backV; @end @implementation HSQCommunityCell + (instancetype)cellWithTableView:(UITableView *)tableView { static NSString *cellID = nil; cellID = NSStringFromClass([self class]); HSQCommunityCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (!cell) { cell = [[HSQCommunityCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } return cell; } - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self initSubViews]; } return self; } - (void)initSubViews { [self.contentView addSubview:self.iconView]; [self.contentView addSubview:self.userName]; [self.contentView addSubview:self.goodImgV]; [self.contentView addSubview:self.goodNamelabel]; [self.contentView addSubview:self.pricelabel]; [self.contentView addSubview:self.commissionLabel]; [self.contentView addSubview:self.shareBtn]; [self.contentView addSubview:self.vouchersLabel]; [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.top.mas_equalTo(14); make.width.height.mas_equalTo(19); }]; [self.userName mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(14); make.left.mas_equalTo(self.iconView.mas_right).mas_offset(10); }]; [self.goodImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(FITSIZE(10)); make.top.mas_equalTo(FITSIZE(40)); make.width.height.mas_equalTo(FITSIZE(100)); }]; [self.goodNamelabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(FITSIZE(40)); make.left.mas_equalTo(self.goodImgV.mas_right).mas_offset(10); make.width.mas_equalTo(FITSIZE(229)); make.height.mas_equalTo(FITSIZE(40)); }]; [self.pricelabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(FITSIZE(87)); make.left.mas_equalTo(self.goodImgV.mas_right).mas_offset(10); }]; [self.commissionLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(FITSIZE(87)); make.right.mas_equalTo(FITSIZE(-20)); }]; [self.vouchersLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.goodImgV.mas_right).mas_offset(10); make.top.mas_equalTo(FITSIZE(119)); make.width.mas_equalTo(FITSIZE(68)); make.height.mas_equalTo(FITSIZE(20)); }]; [self.shareBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(FITSIZE(119)); make.right.mas_equalTo(FITSIZE(-10)); }]; _backV =[[UIView alloc]initWithFrame:CGRectMake(FITSIZE(10), FITSIZE(155), FITSIZE(338), FITSIZE(98))]; _backV.backgroundColor=[UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1.0]; [self.contentView addSubview:_backV]; [_backV addSubview:self.backtiellabel]; [self.backtiellabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(FITSIZE(4)); make.right.mas_equalTo(FITSIZE(-4)); make.top.mas_equalTo(FITSIZE(5)); }]; UIButton *copyBtn =[[UIButton alloc]initWithFrame:CGRectMake(FITSIZE(270), FITSIZE(71), FITSIZE(58), FITSIZE(20))]; copyBtn.layer.cornerRadius=4; copyBtn.layer.borderColor=[UIColor YHColorWithHex:0xF4150D].CGColor; copyBtn.layer.borderWidth=0.5; copyBtn.layer.masksToBounds=YES; [copyBtn setTitle:@"复制素材" forState:UIControlStateNormal]; [copyBtn setTitleColor:[UIColor YHColorWithHex:0xF4150D] forState:UIControlStateNormal]; copyBtn.titleLabel.font=[UIFont systemFontOfSize:FITSIZE(11)]; [_backV addSubview:copyBtn]; [copyBtn addTarget:self action:@selector(copyClickBtn) forControlEvents:UIControlEventTouchUpInside]; } -(void)copyClickBtn { if (self.model.texts.length > 0) { UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; // pasteboard.string =[NSString stringWithFormat:@"%@\n--------\n【在售价】%@元\n【券后价】%@元\n--------\n复制这条信息¥%@¥\n打开【手机淘宝】即可查看",self.model.title,self.model.originalPrice,self.model.ticketAfterPrice,self.model.infoStr]; pasteboard.string=self.model.texts; [SVProgressHUD showSuccessWithStatus:@"复制成功"]; }else { [SVProgressHUD showErrorWithStatus:@"复制失败"]; } [MobClick event:FaddishNormalCopyContent]; } - (void)setModel:(HSQCommunityDetailModel *)model { _model = model; // 时间分享 self.userName.text = model.shop_title;//店铺名称 if (model.shop_type.integerValue == 1) {//天猫 self.iconView.image =[UIImage imageNamed:@"tm_shop"]; }else{ self.iconView.image =[UIImage imageNamed:@"taobao_shop"]; } if (model.img &&![@"" isEqualToString:model.img] && model.img.length>5) { [self.goodImgV sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil]; }else{ [self.goodImgV setImage:[UIImage imageNamed:@"login"]]; } self.goodNamelabel.text=model.title; NSString *discount_price = [NSString stringWithFormat:@"券后¥%.2f",[model.discount_price floatValue]]; NSMutableAttributedString *disAttr = [[NSMutableAttributedString alloc] initWithString:discount_price]; [disAttr yy_setFont:[UIFont systemFontOfSize:13] range:NSMakeRange(0, 2)]; [disAttr yy_setFont:[UIFont systemFontOfSize:15] range:NSMakeRange(3, discount_price.length-3)]; disAttr.yy_color = [UIColor YHColorWithHex:0x333333]; self.pricelabel.attributedText=disAttr; if (model.commission_price.length !=0) { self.commissionLabel.text=[NSString stringWithFormat:@"预估佣金:¥%@",model.commission_price]; } self.vouchersLabel.text=[NSString stringWithFormat:@"券¥%@",model.coupon_price]; if (model.texts.length == 0) { _backV.hidden=YES; }else{ _backV.hidden=NO; //行间距 NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:model.texts]; NSRange range = [model.texts rangeOfString:model.texts]; [attr addAttribute:NSForegroundColorAttributeName value:[UIColor YHColorWithHex:0x333333] range:range]; NSMutableParagraphStyle * mParagraphStyle = [[NSMutableParagraphStyle alloc] init]; mParagraphStyle.lineSpacing = 5; [attr addAttribute:NSParagraphStyleAttributeName value:mParagraphStyle range:range]; self.backtiellabel.attributedText = attr; } } #pragma mark -事件 -(void)oneTouchShareAction{ if (self.delegate && [self.delegate respondsToSelector:@selector(oneTouchShareWithModel:)]) { [self.delegate oneTouchShareWithModel:self.model]; } } - (void)shareAction { if (self.shareClick) { self.shareClick(); } } #pragma mark ---- layzer ---- - (UIImageView *)iconView { if (!_iconView) { _iconView = [[UIImageView alloc] init]; _iconView.backgroundColor = [UIColor yhGrayColor]; } return _iconView; } - (UILabel *)userName { if (!_userName) { _userName = [[UILabel alloc] init]; _userName.textColor = [UIColor YHColorWithHex:0x333333]; _userName.font = [UIFont systemFontOfSize:15]; } return _userName; } - (UILabel *)timeLabel { if (!_timeLabel) { _timeLabel = [[UILabel alloc] init]; _timeLabel.font = [UIFont systemFontOfSize:12]; _timeLabel.textColor = [UIColor YHColorWithHex:0x999999]; _timeLabel.text=@"a"; } return _timeLabel; } - (UILabel *)contentLabel { if (!_contentLabel) { _contentLabel = [[CCCopyLabel alloc] init]; _contentLabel.textColor = [UIColor YHColorWithHex:0x555555]; _contentLabel.font = [UIFont systemFontOfSize:16]; _contentLabel.numberOfLines = 0; } return _contentLabel; } - (PhotoContainerView *)picContainerView { if (!_picContainerView) { _picContainerView = [PhotoContainerView new]; } return _picContainerView; } - (UIView *)bottomLine { if (!_bottomLine) { _bottomLine = [[UIView alloc] init]; _bottomLine.backgroundColor = [UIColor yhGrayColor]; } return _bottomLine; } -(UIButton *)oneTouchShareButton{ if (!_oneTouchShareButton) { _oneTouchShareButton=[UIButton buttonWithType:UIButtonTypeCustom]; [_oneTouchShareButton setImage:[UIImage imageNamed:@"right_share"] forState:UIControlStateNormal]; [_oneTouchShareButton addTarget:self action:@selector(oneTouchShareAction) forControlEvents:UIControlEventTouchUpInside]; } return _oneTouchShareButton; } -(UIImageView *)goodImgV { if (!_goodImgV) { _goodImgV =[[UIImageView alloc]init]; _goodImgV.backgroundColor = [UIColor yhGrayColor]; } return _goodImgV; } -(UILabel *)pricelabel { if (!_pricelabel) { _pricelabel =[[UILabel alloc]init]; _pricelabel.textColor=[UIColor YHColorWithHex:0x333333]; _pricelabel.font=[UIFont systemFontOfSize:FITSIZE(14)]; } return _pricelabel; } -(UILabel *)goodNamelabel { if (!_goodNamelabel) { _goodNamelabel =[[UILabel alloc]init]; _goodNamelabel.numberOfLines=0; _goodNamelabel.textColor=[UIColor YHColorWithHex:0x333333]; _goodNamelabel.font=[UIFont systemFontOfSize:FITSIZE(14)]; } return _goodNamelabel; } -(UILabel *)commissionLabel { if (!_commissionLabel) { _commissionLabel =[[UILabel alloc]init]; _commissionLabel.textColor=[UIColor YHColorWithHex:0xF5122A]; _commissionLabel.font=[UIFont systemFontOfSize:FITSIZE(13)]; _commissionLabel.textAlignment=NSTextAlignmentRight; } return _commissionLabel; } -(UILabel *)vouchersLabel { if (!_vouchersLabel) { _vouchersLabel =[[UILabel alloc]init]; _vouchersLabel.textColor=[UIColor YHColorWithHex:0xF4150D]; _vouchersLabel.font=[UIFont systemFontOfSize:FITSIZE(12)]; _vouchersLabel.layer.borderColor=[UIColor YHColorWithHex:0xF4150D].CGColor; _vouchersLabel.layer.borderWidth=0.4; _vouchersLabel.layer.masksToBounds=YES; _vouchersLabel.textAlignment=NSTextAlignmentCenter; } return _vouchersLabel; } - (UIButton *)shareBtn { if (!_shareBtn) { _shareBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_shareBtn setImage:[UIImage imageNamed:@"comm_share"] forState:UIControlStateNormal]; [_shareBtn addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside]; } return _shareBtn; } -(UILabel *)backtiellabel { if (!_backtiellabel) { _backtiellabel =[[UILabel alloc]init]; _backtiellabel.textColor=[UIColor YHColorWithHex:0x262626]; _backtiellabel.font=[UIFont systemFontOfSize:FITSIZE(13)]; _backtiellabel.numberOfLines=3; } return _backtiellabel; } @end