|
//
// AnswerQuoBaseCell.m
// ThePaperBase
//
// Created by zhousan on 15/11/6.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "AnswerQuoBaseCell.h"
@implementation AnswerQuoBaseCell
@synthesize isMe = _isMe;
- (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.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];
[self.commentBack addSubview:self.quoContentLabel];
[self.commentBack addSubview:self.diandiandianLabel];
[self subLayoutSubViews];
}
return self;
}
- (void)dealloc {
self.backView = nil;
self.commentBack = nil;
self.quoContentLabel = nil;
self.quoNameLable = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
-(void)setIsMe:(BOOL)me{
_isMe = me;
}
- (void)setCommentBO:(commentObjectVO *)data {
_commentBO = data;
if (_isMe) {
self.quoNameLable.text = @"我:";
}else{
self.quoNameLable.text = [NSString stringWithFormat:@"%@:",data.userName];
}
self.quoContentLabel.attributedText = getLineSpaceAttributedString(data.content, 10, appFont(interactionFontSize, NO));
self.quoContentHeight = data.labelHeight;
// self.quoContentHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(data.content, 10, appFont(interactionFontSize, NO)), 930/2, appFont(interactionFontSize, NO));
CGFloat twoLine = twoLineheight;
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
[self reLayoutSubViews];
}
- (UIView *)backView {
if (!_backView) {
_backView = [[UIView alloc]initWithFrame:CGRectZero];
_backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
}
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;
}
- (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) {
[MobClick event:@"56"];
self.commentBO.isQuoExpand = @"1";
}else {
self.commentBO.isQuoExpand = @"0";
}
CGFloat answerContentHeight = 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:BLUECOLOR];
_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;
}
- (UILabel *)quoContentLabel {
if (!_quoContentLabel) {
_quoContentLabel = [UILabel new];
_quoContentLabel.textColor = [UIColor colorWithHexString:TextGray];
_quoContentLabel.textAlignment = NSTextAlignmentLeft;
_quoContentLabel.lineBreakMode = NSLineBreakByWordWrapping;
_quoContentLabel.numberOfLines = 0;
_quoContentLabel.font = appFont(interactionFontSize,NO);
}
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(90);
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;
CGFloat diandianHeight = 0;
if (!self.commentBO.isQuoExpand || [self.commentBO.isQuoExpand intValue] == 0) {
labeHeight = self.commentBO.labelHeight;
if (labeHeight > twoLineheight) {
labeHeight = twoLineheight;
backHeight += 15;
diandianHeight = 15;
}
backHeight += labeHeight;
}else {
labeHeight = self.commentBO.labelHeight;
backHeight += labeHeight;
}
[self.commentBack remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf.backView.left).offset(90);
make.top.equalTo(weakSelf.backView.top).offset(7);
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));
}];
}
- (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
|