|
//
// msgAskIconBaseCell.m
// ThePaperBase
//
// Created by YoungLee on 15/11/18.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "msgAskIconCell.h"
@implementation msgAskIconCell
@synthesize commentBO = _commentBO;
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
[self.backView removeFromSuperview];
[self.contentView addSubview:self.backView];
[self.backView addSubview:self.answerLabel];
// [self.backView addSubview:self.fastComment];
self.timeLabel.hidden = YES;//时间
self.timeImg.hidden = YES;//时间icon
self.iconBack.hidden = YES;//头像原框
self.answerIcon.hidden = YES;
self.verifyTag.hidden = YES;
self.commentImg.hidden = YES;
self.UserInfoBtn.hidden = YES;
self.attentionBtn.hidden = YES;
self.askAuthorLabel.textColor = [UIColor colorWithHexString:BLUECOLOR];
[self setLayoutSubView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
}
return self;
}
- (void)needrefreshNightMode:(id)sender{
self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.timeLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY];
[self.attentionBtn setTitleColor:[UIColor colorWithHexString:LIGHTGRAY] forState:UIControlStateNormal];
self.attentionBtn.layer.borderColor = [UIColor colorWithHexString:LINECOLOR].CGColor;
[self.replyButton setTitleColor:[UIColor colorWithHexString:LIGHTGRAY] forState:UIControlStateNormal];
self.replyButton.layer.borderColor = [UIColor colorWithHexString:LINECOLOR].CGColor;
self.askAuthorLabel.textColor = [UIColor colorWithHexString:TextBlack];
self.anserNumsLabel.textColor = [UIColor colorWithHexString:BLUECOLOR];
self.topicNumsLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY];
self.iconBack.image = [TPUserDefault instance].isNightMode.intValue > 0 ? Image(@"detailPage/icon_night.png") :Image(@"detailPage/icon_sun.png");
self.answerLabel.textColor = [UIColor colorWithHexString:TextBlack];
}
-(UILabel *)answerLabel{
if (!_answerLabel) {
_answerLabel = [UILabel new];
_answerLabel.textColor = [UIColor colorWithHexString:TextBlack];
_answerLabel.font = appFont(8, NO);
_answerLabel.text = @"个回答";
_answerLabel.hidden = YES;
}
return _answerLabel;
}
-(void)setCommentBO:(commentObjectVO *)comment{
_commentBO = comment;
userBO *user = setJsonDicToDataModel(_commentBO.userInfo, [userBO class]);
if (!comment.parentInfo) {
self.anserNumsLabel.hidden = NO;
self.answerLabel.hidden = NO;
if ([[TPUserDefault instance].userBO.userId intValue] == [user.userId intValue]) {
self.askAuthorLabel.text = @"我:";
}else{
self.askAuthorLabel.text = [NSString stringWithFormat:@"%@:",user.sname];
}
self.anserNumsLabel.text = _commentBO.answerNums?_commentBO.answerNums:@"";
}else{
self.anserNumsLabel.hidden = YES;
self.answerLabel.hidden = YES;
userBO *user = setJsonDicToDataModel(comment.parentInfo[@"userInfo"], [userBO class]);
if ([[TPUserDefault instance].userBO.userId intValue] == [user.userId intValue]) {
self.askAuthorLabel.text = @"我:";
}else{
self.askAuthorLabel.text = [NSString stringWithFormat:@"%@:",user.sname];
}
}
[self reLayoutSubViews];
}
-(void) setLayoutSubView{
__weak typeof(self) weakSelf = self;
[self.backView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf.contentView.left).offset(10);
make.right.equalTo(weakSelf.contentView.right).offset(-10);
make.top.equalTo(weakSelf.contentView.top);
make.bottom.equalTo(weakSelf.contentView.bottom);
}];
[self.backBtn makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(weakSelf.backView);
}];
[self.nameButton makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(weakSelf.askAuthorLabel);
}];
}
-(void) fastCommentSelector:(UIButton *) btn{
if ([self.delegate respondsToSelector:@selector(askIconBaseGotoComment:)]) {
[self.delegate askIconBaseGotoComment:self.commentBO];
}
}
- (void)reLayoutSubViews {
CGFloat width = returnTextWidthWithRTLabel(self.anserNumsLabel.text, 10, appFont(8, NO), 0)+5;
CGFloat nameWidth = returnTextWidthWithRTLabel(self.askAuthorLabel.text, 10, appFont(11, NO), 0)+5;
__weak typeof(self) weakSelf = self;
[self.askAuthorLabel remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf.backView.left).offset(10);
make.top.equalTo(weakSelf.backView.top).offset(10);
make.height.mas_equalTo(14);
make.width.mas_equalTo(nameWidth);
}];
[self.nameButton remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.askAuthorLabel.left).offset(-5);
make.right.equalTo(self.askAuthorLabel.right).offset(5);
make.top.equalTo(self.askAuthorLabel.top).offset(-5);
make.bottom.equalTo(self.askAuthorLabel.bottom).offset(5);
}];
[self.answerLabel remakeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(25);
make.right.equalTo(weakSelf.backView.right).offset(-10);
make.centerY.equalTo(weakSelf.askAuthorLabel.centerY);
make.height.mas_equalTo(12);
}];
[self.anserNumsLabel remakeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(weakSelf.answerLabel.left);
make.centerY.equalTo(weakSelf.askAuthorLabel.centerY);
make.height.mas_equalTo(12);
make.width.mas_equalTo(width);
}];
}
@end
|