// // HSQTimeLineTableCell.m // YouHuiProject // // Created by 小花 on 2018/12/27. // Copyright © 2018年 kuxuan. All rights reserved. // #import "HSQTimeLineTableCell.h" #import "HSQTimeLineCommentView.h" #import "UIView+SDAutoLayout.h" #import "CCCopyLabel.h" @interface HSQTimeLineTableCell () @property (nonatomic, strong) UIImageView *iconView; @property (nonatomic, strong) UILabel *name; @property (nonatomic, strong) CCCopyLabel *title; @property (nonatomic, strong) UIView *goodBg; @property (nonatomic, strong) UIImageView *goodIcon; @property (nonatomic, strong) UILabel *goodTitle; @property (nonatomic, strong) UILabel *disPrice; //@property (nonatomic, strong) UILabel *localLabel; @property (nonatomic, strong) UILabel *timeLabel; @property (nonatomic, strong) UIButton *shareButton; //@property (nonatomic, strong) HSQTimeLineCommentView *commentView; @property (nonatomic, strong) UIImageView *ticketNumber; // @property (nonatomic, strong) UILabel *zheKou; // 几折,或者几元券 @property (nonatomic, strong) UILabel *ticketType; @property (nonatomic, strong) UIView *tapView; @end @implementation HSQTimeLineTableCell - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } + (instancetype)cellWithTableView:(UITableView *)tableView { static NSString *cellID = nil; cellID = NSStringFromClass([self class]); HSQTimeLineTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (!cell) { cell = [[HSQTimeLineTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } return cell; } - (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.name]; [self.contentView addSubview:self.title]; [self.contentView addSubview:self.goodBg]; [self.goodBg addSubview:self.goodIcon]; [self.goodBg addSubview:self.goodTitle]; [self.goodBg addSubview:self.disPrice]; [self.goodBg addSubview:self.ticketNumber]; [self.goodBg addSubview:self.tapView]; [self.ticketNumber addSubview:self.ticketType]; [self.ticketNumber addSubview:self.zheKou]; // [self.contentView addSubview:self.localLabel]; [self.contentView addSubview:self.timeLabel]; [self.contentView addSubview:self.shareButton]; // [self.contentView addSubview:self.commentView]; [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.top.mas_equalTo(14); make.width.height.mas_equalTo(42); }]; [self.name mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.iconView.mas_right).mas_offset(10); make.top.mas_equalTo(17); make.right.mas_equalTo(-10); }]; [self.title mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.name.mas_bottom).mas_offset(7); make.left.mas_equalTo(self.name); make.right.mas_equalTo(-10); }]; [self.goodBg mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.name); make.right.mas_equalTo(-10); make.top.mas_equalTo(self.title.mas_bottom).mas_offset(7); make.height.mas_equalTo(90); }]; [self.tapView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0)); }]; // [self.localLabel mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.mas_equalTo(self.goodBg); // make.right.mas_equalTo(-10); // make.top.mas_equalTo(self.goodBg.mas_bottom).mas_offset(8); // }]; [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.goodBg); make.top.mas_equalTo(self.goodBg.mas_bottom).mas_offset(8); make.right.mas_equalTo(-10); }]; [self.shareButton mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-10); make.centerY.mas_equalTo(self.timeLabel.mas_centerY); make.width.mas_equalTo(50); make.height.mas_equalTo(20); }]; [self.goodIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.mas_equalTo(5); make.width.height.mas_equalTo(80); }]; [self.goodTitle mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.goodIcon.mas_right).mas_offset(7); make.right.mas_equalTo(-7); make.top.mas_equalTo(self.goodIcon.mas_top).mas_offset(4); }]; [self.disPrice mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.goodTitle); make.centerY.mas_equalTo(self.goodIcon.mas_centerY); }]; [self.ticketNumber mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.goodTitle.mas_left); make.width.mas_equalTo(64); make.height.mas_equalTo(14); make.bottom.mas_equalTo(-10); }]; [self.ticketType mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.bottom.mas_equalTo(0); make.width.mas_equalTo(20); }]; [self.zheKou mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.ticketType.mas_right); make.top.mas_equalTo(0); make.height.mas_equalTo(14); make.width.mas_equalTo(44); }]; // _commentView.sd_layout // .leftEqualToView(self.name) // .rightSpaceToView(self.contentView, 10) // .topSpaceToView(_timeLabel, 10); } - (void)shareClick { if (self.shareClickBlock) { self.shareClickBlock(); } } -(void)setLineSpace:(CGFloat)lineSpace withText:(NSString *)text inLabel:(UILabel *)label{ if (!text || !label) { return; } NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.lineSpacing = lineSpace; //设置行间距 paragraphStyle.lineBreakMode = label.lineBreakMode; // paragraphStyle.alignment = label.textAlignment; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text]; [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])]; label.attributedText = attributedString; } - (void)setModel:(HSQTimeLineModel *)model { _model = model; [self.iconView sd_setFadeImageWithURL:[NSURL URLWithString:model.subscribe_img] placeholderImage:nil options:0 progress:nil completed:nil]; self.name.text = model.subscribe_title; // self.title.text = model.show_content; [self setLineSpace:4 withText:model.show_content inLabel:self.title]; [self.goodIcon sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil];; self.goodTitle.text = model.title; self.disPrice.text = [NSString stringWithFormat:@"¥%@",model.discount_price]; self.timeLabel.text = model.pass_time; // self.localLabel.text = model.location; //折后价 NSString *disStr; if ([model.is_coupon boolValue]) { disStr = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]]; self.zheKou.text = [NSString stringWithFormat:@"%@元",model.coupon_price]; self.ticketType.text = @"券"; }else { disStr = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]]; self.zheKou.text = [NSString stringWithFormat:@"%@折",model.coupon_price]; self.ticketType.text = @"折"; } //券相关 self.ticketNumber.hidden = ![model.is_coupon boolValue]; UIView *bottomView; bottomView = _timeLabel; // [self.commentView setupWithLikeItemsArray:model.shareUser contentText:model.show_comment]; // if (!model.shareUser.count && model.show_comment.length==0) { // bottomView = _timeLabel; // } else { // bottomView = _commentView; // } [self setupAutoHeightWithBottomView:bottomView bottomMargin:15]; } - (void)tapAction { if (self.tapBlock) { self.tapBlock(); } } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (UIImageView *)iconView { if (!_iconView) { _iconView = [[UIImageView alloc] init]; _iconView.layer.cornerRadius = 21; _iconView.layer.masksToBounds = YES; _iconView.backgroundColor = [UIColor yhGrayColor]; } return _iconView; } - (UILabel *)name { if (!_name) { _name = [[UILabel alloc] init]; _name.font = [UIFont boldSystemFontOfSize:17]; _name.textColor = [UIColor YHColorWithHex:0x576B95]; } return _name; } - (CCCopyLabel *)title { if (!_title) { _title = [[CCCopyLabel alloc] init]; _title.font = [UIFont fontWithName:@"HelveticaNeue" size:17]; _title.textColor = [UIColor YHColorWithHex:0x222222]; _title.numberOfLines = 0; _title.longTapBlock = ^{ [MobClick event:OptimizingCircleCopyTopContent]; }; } return _title; } - (UIView *)goodBg { if (!_goodBg) { _goodBg = [[UIView alloc] init]; _goodBg.backgroundColor = [UIColor YHColorWithHex:0xF3F3F5 alpha:0.9]; } return _goodBg; } //- (UILabel *)localLabel { // if (!_localLabel) { // _localLabel = [[UILabel alloc] init]; // _localLabel.font = [UIFont systemFontOfSize:14]; // _localLabel.textColor = [UIColor YHColorWithHex:0x576B95]; // } // return _localLabel; //} - (UILabel *)timeLabel { if (!_timeLabel) { _timeLabel = [[UILabel alloc] init]; _timeLabel.font = [UIFont systemFontOfSize:14]; _timeLabel.textColor = [UIColor YHColorWithHex:0xB2B2B2]; } return _timeLabel; } - (UIButton *)shareButton { if (!_shareButton) { _shareButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_shareButton setTitle:@"分享" forState:UIControlStateNormal]; _shareButton.layer.cornerRadius = 10; _shareButton.layer.borderColor = [UIColor YHColorWithHex:0x576B95].CGColor; _shareButton.layer.borderWidth = 1; [_shareButton setTitleColor:[UIColor YHColorWithHex:0x576B95] forState:UIControlStateNormal]; _shareButton.titleLabel.font = [UIFont systemFontOfSize:11]; [_shareButton addTarget:self action:@selector(shareClick) forControlEvents:UIControlEventTouchUpInside]; } return _shareButton; } - (UIImageView *)goodIcon { if (!_goodIcon) { _goodIcon = [[UIImageView alloc] init]; _goodIcon.backgroundColor = [UIColor whiteColor]; } return _goodIcon; } - (UILabel *)goodTitle { if (!_goodTitle) { _goodTitle = [[UILabel alloc] init]; _goodTitle.font = [UIFont systemFontOfSize:14]; _goodTitle.textColor = [UIColor blackColor]; } return _goodTitle; } - (UILabel *)disPrice { if (!_disPrice) { _disPrice = [[UILabel alloc] init]; _disPrice.textColor = [UIColor homeRedColor]; _disPrice.font = [UIFont systemFontOfSize:16]; } return _disPrice; } //- (HSQTimeLineCommentView *)commentView { // if (!_commentView) { // _commentView = [HSQTimeLineCommentView new]; // } // return _commentView; //} - (UIImageView *)ticketNumber { if (!_ticketNumber) { _ticketNumber = [[UIImageView alloc] init]; _ticketNumber.image = [UIImage imageNamed:@"tickY"]; } return _ticketNumber; } - (UILabel *)zheKou { if (!_zheKou) { _zheKou = [[UILabel alloc] init]; _zheKou.textColor = [UIColor homeRedColor]; _zheKou.textAlignment = NSTextAlignmentCenter; _zheKou.font = [UIFont systemFontOfSize:10]; } return _zheKou; } - (UILabel *)ticketType { if (!_ticketType) { _ticketType = [[UILabel alloc] init]; _ticketType.font = [UIFont systemFontOfSize:10]; _ticketType.textAlignment = NSTextAlignmentCenter; _ticketType.textColor = [UIColor homeRedColor]; } return _ticketType; } - (UIView *)tapView { if (!_tapView) { _tapView = [[UIView alloc] init]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)]; [_tapView addGestureRecognizer:tap]; } return _tapView; } @end