|
//
// AskContentBaseCell.m
// ThePaperBase
//
// Created by zhousan on 15/11/9.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "AskContentBaseCell.h"
@implementation AskContentBaseCell
- (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 addSubview:self.askContentLabel];
[self.backView addSubview:self.backBtn];
self.lineView = [[UIImageView alloc] initWithFrame:CGRectZero];
self.lineView.image = Image(@"topic/dottedLine.png");
[self.backView addSubview:self.lineView];
[self.backView addSubview:self.menuButton];
[self subLayoutSubViews];
// self.backView.backgroundColor = [UIColor greenColor];
[[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.askContentLabel.textColor = [UIColor colorWithHexString:TextBlack];
self.lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
[self.askContentLabel setNeedsDisplay];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (TPEmojiLabel *)askContentLabel {
if (!_askContentLabel) {
_askContentLabel = [[TPEmojiLabel alloc]initWithFrame:CGRectMake(10, 0, rect_screen.size.width - 20, 0) LineSpace:10 ParagraphSpacing:0];
_askContentLabel.lineBreakMode = NSLineBreakByCharWrapping;
_askContentLabel.textColor = [UIColor colorWithHexString:TextBlack];
_askContentLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO);
}
return _askContentLabel;
}
- (void)setCommentBO:(commentObjectVO *)data {
_commentBO = data;
NSInvocationOperation *operation = [[NSInvocationOperation alloc]initWithTarget:self
selector:@selector(readyToReLayout)
object:nil];
[[TPUserDefault instance].globalQueue addOperation:operation];
}
- (void)readyToReLayout {
[self performSelectorOnMainThread:@selector(updateCellUI) withObject:nil waitUntilDone:YES];
// usleep(1);
}
- (void)updateCellUI {
self.askContentLabel.text = _commentBO.content?_commentBO.content:@"";
self.cellHeight = (int)_commentBO.labelHeight;
if (_commentBO.answerList.count == 0) {
self.lineView.hidden = YES;
}else self.lineView.hidden = NO;
[self reLayoutSubViews];
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (UIButton *)backBtn {
if (!_backBtn) {
_backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_backBtn.frame = CGRectZero;
_backBtn.backgroundColor = [UIColor clearColor];
[_backBtn addTarget:self action:@selector(gotoHotAskWithVO:) forControlEvents:UIControlEventTouchUpInside];
}
return _backBtn;
}
- (UIView *)backView {
if (!_backView) {
_backView = [[UIView alloc]initWithFrame:CGRectZero];
_backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
}
return _backView;
}
- (UIButton*)menuButton {
if (!_menuButton) {
_menuButton = [UIButton buttonWithType:UIButtonTypeCustom];
_menuButton.frame = CGRectZero;
_menuButton.backgroundColor = [UIColor clearColor];
[_menuButton addTarget:self action:@selector(menuTap:) forControlEvents:UIControlEventTouchUpInside];
}
return _menuButton;
}
- (void)gotoHotAskWithVO:(id)sender {
if ([self.delegate respondsToSelector:@selector(gotoHotAskWithCommentVO:)]) {
[self.delegate gotoHotAskWithCommentVO:self.commentBO];
}
}
- (void)reLayoutSubViews {
__weak typeof(self) weakSelf = self;
[self.askContentLabel remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf.backView.left).offset(10);
make.top.equalTo(weakSelf.backView);
make.height.mas_equalTo(weakSelf.cellHeight);
make.right.equalTo(weakSelf.backView.right).offset(-10);
}];
}
- (void)subLayoutSubViews {
__weak typeof(self) weakSelf = self;
[self.backView makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(weakSelf);
}];
[self.backBtn makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(weakSelf.backView);
}];
[self.lineView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf.backView.left).offset(10);
make.bottom.equalTo(weakSelf.backView.bottom);
make.width.equalTo(weakSelf.backView.width).offset(-20);
make.height.mas_equalTo(0.5);
}];
}
@end
|