// // AnswerQuoBaseCell.m // ThePaperBase // // Created by zhousan on 15/11/6. // Copyright © 2015年 scar1900. All rights reserved. // #import "AnswerQuoBaseCell.h" @implementation AnswerQuoBaseCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.selectionStyle = UITableViewCellSelectionStyleNone; self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; [self addSubview:self.backView]; // self.backView.backgroundColor = [UIColor greenColor]; self.lineView = [[UIView alloc] initWithFrame:CGRectZero]; self.lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; [self.backView addSubview:self.lineView]; self.havePic = NO; [self.backView addSubview:self.commentBack]; [self.backView addSubview:self.triangleImg]; [self.commentBack addSubview:self.quoNameLable]; UITapGestureRecognizer *picTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(picTap:)]; UITapGestureRecognizer *picTap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(picTap:)]; UITapGestureRecognizer *picTap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(picTap:)]; [self.backView addSubview:self.quoPic1]; [self.backView addSubview:self.quoPic2]; [self.backView addSubview:self.quoPic3]; [self.quoPic1 addGestureRecognizer:picTap1]; [self.quoPic2 addGestureRecognizer:picTap2]; [self.quoPic3 addGestureRecognizer:picTap3]; [self.commentBack addSubview:self.quoContentLabel]; [self.commentBack addSubview:self.diandiandianLabel]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; [self subLayoutSubViews]; } return self; } - (void)needrefreshNightMode:(id)sender{ self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; _lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; _backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; _commentBack.layer.borderColor = [UIColor colorWithHexString:LINECOLOR].CGColor; _quoNameLable.textColor = [UIColor colorWithHexString:TextGray]; _quoContentLabel.textColor = [UIColor colorWithHexString:TextGray]; _triangleImg.image = [[TPUserDefault instance].isNightMode intValue] > 0 ?Image(@"other/commentBack_triangle_night.png"):Image(@"other/commentBack_triangle.png"); [self.quoContentLabel setNeedsDisplay]; } - (void)dealloc { self.backView = nil; self.commentBack = nil; self.quoContentLabel = nil; self.quoNameLable = nil; [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)setCommentBO:(commentObjectVO *)data { _commentBO = data; self.quoNameLable.text = [NSString stringWithFormat:@"%@:",data.userName]; self.quoContentLabel.text = data.content; self.quoContentHeight = (int)data.labelHeight; CGFloat twoLine = getLineHeightWithCountAndFontWidth(2, 10, TEXT_FOUR_LEVELSIZE); if (self.quoContentHeight <= twoLine) { self.commentBack.userInteractionEnabled = NO; self.diandiandianLabel.hidden = YES; }else{ self.commentBack.userInteractionEnabled = YES; self.diandiandianLabel.hidden = NO; } if (!data.isQuoExpand || [data.isQuoExpand intValue] == 0) { self.quoContentHeight = self.quoContentHeight>twoLine?twoLine:self.quoContentHeight; }//TODO如果有图片havePic设为YES if (data.imageList.count > 0) { switch (data.imageList.count) { case 1: self.quoPic1.hidden = NO; self.quoPic2.hidden = YES; self.quoPic3.hidden = YES; break; case 2: self.quoPic1.hidden = NO; self.quoPic2.hidden = NO; self.quoPic3.hidden = YES; break; case 3: self.quoPic1.hidden = NO; self.quoPic2.hidden = NO; self.quoPic3.hidden = NO; break; default: break; } self.havePic = YES; [data.imageList enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { imageObjectBO *image = obj; switch (idx) { case 0: self.quoPic1.imageUrl = image.url; self.quoPic1.imageId = getImageNameFromURL(image.url); break; case 1: self.quoPic2.imageUrl = image.url; self.quoPic2.imageId = getImageNameFromURL(image.url); break; case 2: self.quoPic3.imageUrl = image.url; self.quoPic3.imageId = getImageNameFromURL(image.url); break; default: break; } }]; } if ([data.hiddenLine isEqualToString:@"1"]) { self.lineView.hidden = YES; } [self reLayoutSubViews]; } - (UIView *)backView { if (!_backView) { _backView = [[UIView alloc]initWithFrame:CGRectZero]; _backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; // _backView.backgroundColor = [UIColor blueColor]; } return _backView; } - (UILabel *)diandiandianLabel { if (!_diandiandianLabel) { _diandiandianLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _diandiandianLabel.textColor = [UIColor colorWithHexString:TextGray]; _diandiandianLabel.backgroundColor = [UIColor clearColor]; _diandiandianLabel.font = appFont(20, YES); _diandiandianLabel.text = @"..."; _diandiandianLabel.textAlignment = NSTextAlignmentCenter; _diandiandianLabel.hidden = YES; } return _diandiandianLabel; } - (AsyncImageView *)quoPic1 { if (_quoPic1 == nil) { _quoPic1 = [[AsyncImageView alloc] initWithFrame:CGRectZero]; _quoPic1.tag = 1; _quoPic1.hidden = YES; } return _quoPic1; } - (AsyncImageView *)quoPic2 { if (_quoPic2 == nil) { _quoPic2 = [[AsyncImageView alloc] initWithFrame:CGRectZero]; _quoPic2.tag = 2; _quoPic2.hidden = YES; } return _quoPic2; } - (AsyncImageView *)quoPic3 { if (_quoPic3 == nil) { _quoPic3 = [[AsyncImageView alloc] initWithFrame:CGRectZero]; _quoPic3.tag = 3; _quoPic3.hidden = YES; } return _quoPic3; } - (UIButton *)commentBack { if (!_commentBack) { _commentBack = [[UIButton alloc] initWithFrame:CGRectZero]; self.commentBack.layer.cornerRadius = 5; self.commentBack.layer.borderWidth = 0.7; _commentBack.layer.borderColor = [UIColor colorWithHexString:LINECOLOR].CGColor; [_commentBack addTarget:self action:@selector(quoExandBtnClick:) forControlEvents:UIControlEventTouchUpInside]; } return _commentBack; } - (void)quoExandBtnClick:(UIButton *)btn { if (!self.commentBO.isQuoExpand || [self.commentBO.isQuoExpand intValue] == 0) { self.commentBO.isQuoExpand = @"1"; }else { self.commentBO.isQuoExpand = @"0"; } CGFloat answerContentHeight = (int)self.commentBO.labelHeight; if (quoBlock) { quoBlock([self.commentBO.isQuoExpand boolValue],answerContentHeight); } } - (void)quoBlock:(void (^)(BOOL, CGFloat))block { quoBlock = [block copy]; } - (UILabel*)quoNameLable { if (!_quoNameLable) { _quoNameLable = [[UILabel alloc]initWithFrame:CGRectZero]; _quoNameLable.textColor = [UIColor colorWithHexString:TextGray]; _quoNameLable.textAlignment = NSTextAlignmentLeft; } _quoNameLable.font = appFont(TEXT_SIX_LEVELSIZE,NO); return _quoNameLable; } - (UIImageView *)triangleImg{ if (!_triangleImg) { _triangleImg = [UIImageView new]; _triangleImg.image = [[TPUserDefault instance].isNightMode intValue] > 0 ?Image(@"other/commentBack_triangle_night.png"):Image(@"other/commentBack_triangle.png"); } return _triangleImg; } - (TPEmojiLabel *)quoContentLabel { if (!_quoContentLabel) { _quoContentLabel = [[TPEmojiLabel alloc]initWithFrame:CGRectZero LineSpace:10 ParagraphSpacing:0]; _quoContentLabel.textColor = [UIColor colorWithHexString:TextGray]; _quoContentLabel.textAlignment = NSTextAlignmentLeft; _quoContentLabel.lineBreakMode = NSLineBreakByCharWrapping; _quoContentLabel.font = appFont(TEXT_FOUR_LEVELSIZE,NO); // _quoContentLabel.backgroundColor = [UIColor redColor]; } return _quoContentLabel; } - (void)subLayoutSubViews { __weak typeof(self) weakSelf = self; [self.backView makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self); }]; [self.lineView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(weakSelf.backView.left).offset(10); make.right.equalTo(weakSelf.backView.right).offset(-10); make.bottom.equalTo(weakSelf.backView.bottom); make.height.mas_equalTo(1); }]; [self.quoNameLable makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(weakSelf.commentBack.left).offset(10); make.top.equalTo(weakSelf.commentBack.top).offset(10); make.width.mas_equalTo(weakSelf.commentBack).offset(-15); make.height.mas_equalTo(25/2); }]; [self.triangleImg makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.commentBack.left).offset(55/2); make.top.equalTo(self.commentBack.top).offset(-6); make.width.equalTo(@7); make.height.equalTo(@7); }]; } - (void)reLayoutSubViews { __weak typeof(self) weakSelf = self; CGFloat backHeight = 50/2+10; CGFloat labeHeight = 0; if (self.havePic) { backHeight += 15/2+quo_pic_width; } CGFloat diandianHeight = 0; // CGFloat twoLine = (appFont(TEXT_FOUR_LEVELSIZE, NO).lineHeight + 10)*2 - 10; if (!self.commentBO.isQuoExpand || [self.commentBO.isQuoExpand intValue] == 0) { labeHeight = (int)self.commentBO.labelHeight; if (labeHeight > getLineHeightWithCountAndFontWidth(2, 10, TEXT_FOUR_LEVELSIZE)) { labeHeight = getLineHeightWithCountAndFontWidth(2, 10, TEXT_FOUR_LEVELSIZE); backHeight += 15; diandianHeight = 15; } backHeight += labeHeight; }else { labeHeight = (int)self.commentBO.labelHeight; backHeight += labeHeight; } [self.commentBack remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(weakSelf.backView.left).offset(10); make.top.equalTo(weakSelf.backView.top).offset(10); make.right.equalTo(weakSelf.backView.right).offset(-10); make.height.mas_equalTo(backHeight); }]; [self.quoContentLabel remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.commentBack.left).offset(8); make.top.equalTo(self.quoNameLable.bottom).offset(5); make.right.equalTo(self.commentBack.right).offset(-8); make.height.mas_equalTo(labeHeight); }]; [self.diandiandianLabel remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.quoContentLabel.bottom); make.centerX.equalTo(self.backView); make.size.mas_equalTo(CGSizeMake(100, diandianHeight)); }]; [self.quoPic1 makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.commentBack.left).offset(10); make.top.equalTo(self.diandiandianLabel.bottom).offset(15/2); make.size.mas_equalTo(CGSizeMake(quo_pic_width, quo_pic_width)); }]; [self.quoPic2 makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.quoPic1.right).offset(10); make.top.equalTo(self.diandiandianLabel.bottom).offset(15/2); make.size.mas_equalTo(CGSizeMake(quo_pic_width, quo_pic_width)); }]; [self.quoPic3 makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.quoPic2.right).offset(10); make.top.equalTo(self.diandiandianLabel.bottom).offset(15/2); make.size.mas_equalTo(CGSizeMake(quo_pic_width, quo_pic_width)); }]; } - (void)picTap:(UITapGestureRecognizer *)tap { NSUInteger tag = tap.view.tag; if ([self.delegate respondsToSelector:@selector(tapPicWithIndex:andImageBOArray:)]) { [self.delegate tapPicWithIndex:tag andImageBOArray:self.commentBO.imageList]; } } - (void)awakeFromNib { // Initialization code rampage } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end