|
//
// hitAnwerCell.m
// ThePaperDemo
//
// Created by scar1900 on 14-9-24.
// Copyright (c) 2014年 scar1900. All rights reserved.
//
#import "hitAnwerCell.h"
#import "commentOkButton.h"
@interface hitAnwerCell() {
}
@property(nonatomic, strong)UIView *lineView;
@property(nonatomic, strong)UILabel *askAuthorLabel; //提问者姓名
@property(nonatomic, strong)UILabel *anserNumsLabel; //回答数目显示
@property(nonatomic, strong)RTLabel *askContentLabel; //问题内容
@property(nonatomic, strong)UIButton *askContentButton;
@property(nonatomic, strong)UILabel *anserNameLabel; //回答者姓名
@property(nonatomic, strong)commentOkButton *OkButton; //点赞按钮
@property(nonatomic, strong)RTLabel *aswerContentLabel; //回答详情
@property(nonatomic, strong)UIButton *expandBtn;
@end
@implementation hitAnwerCell
@synthesize commentBO = _commentBO;
@synthesize delegate;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor whiteColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self addSubview:self.lineView];
[self addSubview:self.askAuthorLabel];
[self addSubview:self.anserNumsLabel];
[self addSubview:self.askContentLabel];
[self addSubview:self.askContentButton];
[self addSubview:self.anserNameLabel];
[self addSubview:self.aswerContentLabel];
[self addSubview:self.OkButton];
[self addSubview:self.expandBtn];
}return self;
}
- (UIView*)lineView {
if (!_lineView) {
_lineView = [[UIView alloc]initWithFrame:CGRectZero];
_lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _lineView;
}
- (UILabel*)askAuthorLabel {
if (!_askAuthorLabel) {
_askAuthorLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_askAuthorLabel.textColor = [UIColor colorWithHexString:BLUECOLOR];
_askAuthorLabel.textAlignment = NSTextAlignmentLeft;
}
_askAuthorLabel.font = appFont(11, NO);
return _askAuthorLabel;
}
- (UILabel*)anserNumsLabel {
if (!_anserNumsLabel) {
_anserNumsLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_anserNumsLabel.textColor = [UIColor colorWithHexString:TextGray];
_anserNumsLabel.textAlignment = NSTextAlignmentRight;
}
_anserNumsLabel.font = appFont(11, NO);
return _anserNumsLabel;
}
- (RTLabel*)askContentLabel {
if (!_askContentLabel) {
_askContentLabel = [[RTLabel alloc]initWithFrame:CGRectMake(0, 0, 300, 0)];
_askContentLabel.textColor = [UIColor colorWithHexString:TextBlack];
_askContentLabel.textAlignment = RTTextAlignmentLeft;
_askContentLabel.lineBreakMode = RTTextLineBreakModeWordWrapping;
_askContentLabel.lineSpacing = 7;
}
_askContentLabel.font = appFont(33.2/2, NO);
return _askContentLabel;
}
- (UIButton*)askContentButton {
if (!_askContentButton) {
_askContentButton = [UIButton buttonWithType:UIButtonTypeCustom];
_askContentButton.backgroundColor = [UIColor clearColor];
_askContentButton.frame = CGRectZero;
[_askContentButton addTarget:self action:@selector(goToAskDetail:) forControlEvents:UIControlEventTouchUpInside];
}
return _askContentButton;
}
- (UILabel*)anserNameLabel {
if (!_anserNameLabel) {
_anserNameLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_anserNameLabel.textColor = [UIColor colorWithHexString:TextBlack];
_anserNameLabel.textAlignment = NSTextAlignmentLeft;
}
_anserNameLabel.font = appFont(11, NO);
return _anserNameLabel;
}
- (RTLabel*)aswerContentLabel {
if (!_aswerContentLabel) {
_aswerContentLabel = [[RTLabel alloc]initWithFrame:CGRectMake(0, 0, 270, 0)];
_aswerContentLabel.textColor = [UIColor colorWithHexString:TextGray];
_aswerContentLabel.textAlignment = RTTextAlignmentLeft;
_aswerContentLabel.lineBreakMode = RTTextLineBreakModeWordWrapping;
_aswerContentLabel.lineSpacing = 7;
}
_aswerContentLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO);
return _aswerContentLabel;
}
- (void)setCommentBO:(commentObjectVO *)data {
_commentBO = data;
NSDictionary *dic = data.answerList?data.answerList[0]:nil;
if (dic) {
commentObjectVO *childObject = setJsonDicToDataModel(dic, [commentObjectVO class]);
self.askAuthorLabel.text = data.userName?[NSString stringWithFormat:@"%@:",data.userName]:@"";
self.anserNumsLabel.text = data.answerNums?[NSString stringWithFormat:@"(%@个回答)",data.answerNums]:@"";
self.askContentLabel.text = data.content?data.content:@"";
self.anserNameLabel.text = childObject.userName?[NSString stringWithFormat:@"%@:",childObject.userName]:@"";
self.aswerContentLabel.text = childObject?childObject.content:@"";
self.OkButton.text = childObject.praiseTimes;
CGFloat answerContentHeight = self.aswerContentLabel.optimumSize.height;
if (answerContentHeight > 100) {
self.expandBtn.hidden = NO;
}
}
}
- (commentOkButton*)OkButton {
if (!_OkButton) {
_OkButton = [[commentOkButton alloc]initWithFrame:CGRectZero];
[_OkButton addTarget:self action:@selector(commentOK:) forControlEvents:UIControlEventTouchUpInside];
}
_OkButton.titleLabel.font = appFont(11, NO);
return _OkButton;
}
- (UIButton*)expandBtn {
if (!_expandBtn) {
_expandBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_expandBtn.backgroundColor = [UIColor clearColor];
_expandBtn.hidden = YES;
[_expandBtn setImage:Image(@"detailPage/expandArrow.png") forState:UIControlStateNormal];
[_expandBtn addTarget:self action:@selector(expandEvent:) forControlEvents:UIControlEventTouchUpInside];
_expandBtn.selected = NO;
}
return _expandBtn;
}
- (void)layoutSubviews {
[super layoutSubviews];
self.lineView.frame = CGRectMake(10, CGRectGetHeight(self.bounds)-1, CGRectGetWidth(self.bounds), 1);
self.askAuthorLabel.frame = CGRectMake(10, 25/2, 150, 15);
self.anserNumsLabel.frame = CGRectMake(CGRectGetMaxX(self.askAuthorLabel.frame), 25/2, 150, 15);
CGFloat askContentHeight = returnTextHeightWithRTLabel(self.askContentLabel.text, rect_screen.size.width-20, self.askContentLabel.font,7);
self.askContentLabel.frame = CGRectMake(10, CGRectGetMaxY(self.askAuthorLabel.frame)+15/2, rect_screen.size.width-20, askContentHeight);
self.askContentButton.frame = self.askContentLabel.frame;
self.anserNameLabel.frame = CGRectMake(40, CGRectGetMaxY(self.askContentLabel.frame)+20, rect_screen.size.width-20-30, 15);
CGFloat answerContentHeight = returnTextHeightWithRTLabel(self.aswerContentLabel.text, rect_screen.size.width-20-30, self.aswerContentLabel.font,7);
if (!self.commentBO.isExpand || [self.commentBO.isExpand intValue] == 0) {
answerContentHeight = answerContentHeight>100?100:answerContentHeight;
[_expandBtn setImage:Image(@"detailPage/expandArrow.png") forState:UIControlStateNormal];
}else {
[_expandBtn setImage:Image(@"detailPage/expandArrowUp.png") forState:UIControlStateNormal];
}
self.aswerContentLabel.frame = CGRectMake(CGRectGetMinX(self.anserNameLabel.frame), CGRectGetMaxY(self.anserNameLabel.frame)+15/2, CGRectGetWidth(self.anserNameLabel.frame), answerContentHeight);
self.OkButton.frame = CGRectMake(5, CGRectGetMinY(self.anserNameLabel.frame), 30, 35);
self.expandBtn.frame = CGRectMake(0, CGRectGetMaxY(self.aswerContentLabel.frame), CGRectGetWidth(self.bounds), 34);
[self.expandBtn setImageEdgeInsets:UIEdgeInsetsMake(25/2, CGRectGetWidth(self.expandBtn.frame)/2-13, 13, CGRectGetWidth(self.expandBtn.frame)/2-13)];
}
- (void)commentOK:(UIButton*)btn {
btn.selected = !btn.selected;
}
- (void)expandEvent:(UIButton*)btn {
if (!self.commentBO.isExpand || [self.commentBO.isExpand intValue] == 0) {
self.commentBO.isExpand = @"1";
}else {
self.commentBO.isExpand = @"0";
}
CGFloat answerContentHeight = self.aswerContentLabel.optimumSize.height;
if (expandCell) {
expandCell([self.commentBO.isExpand boolValue],answerContentHeight);
}
}
- (void)expandCell:(void (^)(BOOL, CGFloat))block {
expandCell = [block copy];
}
- (void)goToAskDetail:(UIButton*)button {
if ([self.delegate respondsToSelector:@selector(goToAskDetailPage:)]) {
[self.delegate goToAskDetailPage:self.commentBO];
}
}
- (void)dealloc {
self.lineView = nil;
self.askAuthorLabel = nil;
self.anserNameLabel = nil;
self.askContentLabel = nil;
self.askContentButton = nil;
self.anserNameLabel = nil;
self.OkButton = nil;
self.aswerContentLabel = nil;
self.expandBtn = nil;
}
@end
|