|
//
// topicAskCell.m
// ThePaperHD
//
// Created by scar1900 on 15/5/12.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "topicAskCell.h"
#define tableWidht 1230/2
@interface topicAskCell() {
BOOL isDashed;
CGFloat askContentHeight;
}
@property(nonatomic, strong)UIView* backView;
@property(nonatomic, strong)AsyncImageView *headPicImgView;
@property(nonatomic, strong)UIButton *headBtn;
@property(nonatomic, strong)UIImageView *vipImg;
@property(nonatomic, strong)UILabel *askNameLabel;
@property(nonatomic, strong)UIButton *askNameButton;
@property(nonatomic, strong)UILabel *timeLabel;
@property(nonatomic, strong)RTLabel *askContentLabel;
@property(nonatomic, strong)UIView *lineView;
@property(nonatomic, strong)UIImageView *dashedLineView;
@property(nonatomic, strong)UILabel *answerLabel;
@property(nonatomic, strong)UILabel *answerNumLabel;
@end
@implementation topicAskCell
@synthesize commentBO = _commentBO;
@synthesize padding;
@synthesize isCreat;
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.contentView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[self.contentView addSubview:self.backView];
[self.backView addSubview:self.headPicImgView];
[self.backView addSubview:self.vipImg];
[self.backView addSubview:self.askNameLabel];
[self.backView addSubview:self.askContentLabel];
[self.backView addSubview:self.timeLabel];
[self.backView addSubview:self.answerLabel];
[self.backView addSubview:self.answerNumLabel];
[self.backView addSubview:self.lineView];
[self.backView addSubview:self.dashedLineView];
[self.backView addSubview:self.headBtn];
[self.backView addSubview:self.askNameButton];
}
return self;
}
- (UIView *)backView {
if (!_backView) {
_backView = [[UIView alloc]initWithFrame:CGRectZero];
_backView.backgroundColor = [UIColor clearColor];
}
return _backView;
}
- (UIImageView*)dashedLineView {
if (!_dashedLineView) {
_dashedLineView = [[UIImageView alloc]initWithFrame:CGRectZero];
_dashedLineView.image = Image(@"detailPage/dashedLine.png");
}
return _dashedLineView;
}
- (UIView*)lineView {
if (!_lineView) {
_lineView = [[UIView alloc]initWithFrame:CGRectZero];
_lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _lineView;
}
- (void)setCommentBO:(commentObjectVO *)data {
_commentBO = data;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
userBO *user = setJsonDicToDataModel(data.userInfo, [userBO class]);
NSString *nameStr = user.sname?[NSString stringWithFormat:@"%@:",user.sname]:@"";
askContentHeight = returnTextHeightWithRTLabel(data.content, tableWidht, appFont(interactionFontSize, NO), 10);//【需求变更】话题详情页问答列表的文字字号调整(bug:4445)
NSString *answerNumStr = data.answerNums?[NSString stringWithFormat:@"(%@个回答)",data.answerNums]:@"";
// askContentHeight = returnTextHeightWithRTLabel(data.content, 1170/2, appFont(15, NO),10);
dispatch_async(dispatch_get_main_queue(), ^{
if (data.answerList.count > 0) {
if (!self.isCreat) {
self.lineView.hidden = YES;
self.dashedLineView.hidden = NO;
self.answerLabel.hidden = YES;
self.answerNumLabel.hidden = NO;
}else {
self.lineView.hidden = NO;
self.dashedLineView.hidden = YES;
self.answerLabel.hidden = NO;
self.answerNumLabel.hidden = YES;
}
}else {
self.lineView.hidden = NO;
self.dashedLineView.hidden = YES;
self.answerLabel.hidden = NO;
self.answerNumLabel.hidden = YES;
}
if ([user.isAuth integerValue] ==1) {//认证用户提问或回答,头像不显示加”V“(bug:4116)
self.vipImg.hidden = NO;
}else{
self.vipImg.hidden = YES;
}
self.answerNumLabel.text = answerNumStr;
self.headPicImgView.imageUrl = user.pic;
self.askNameLabel.text = nameStr;
self.askContentLabel.text = data.content;
self.timeLabel.text = data.pubTime;
if (!data.isAnswer || [data.isAnswer intValue] == 0) {
self.answerLabel.text = @"回复";
}else {
self.answerLabel.text = @"已回复";
}
[self layoutSubviews];
});
});
}
- (UILabel*)answerNumLabel {
if (!_answerNumLabel) {
_answerNumLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_answerNumLabel.font = appFont(11, NO);
_answerNumLabel.textColor = [UIColor colorWithHexString:BLUECOLOR];
_answerNumLabel.textAlignment = NSTextAlignmentRight;
_answerNumLabel.backgroundColor = [UIColor clearColor];
}
return _answerNumLabel;
}
- (AsyncImageView*)headPicImgView {
if (!_headPicImgView) {
_headPicImgView = [[AsyncImageView alloc]initWithFrame:CGRectZero];
_headPicImgView.layer.cornerRadius = 35.f/2;
_headPicImgView.clipsToBounds = YES;
_headPicImgView.isHaveWaterPrint = NO;
_headPicImgView.defaultImage = Image(@"setting/loginIcon_s.png");
}
return _headPicImgView;
}
-(UIButton *)headBtn{
if (!_headBtn) {
_headBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_headBtn addTarget:self action:@selector(headBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
}
return _headBtn;
}
-(UIImageView *)vipImg{
if (!_vipImg) {
_vipImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
_vipImg.image = Image(@"setting/vipIcon.png");
_vipImg.hidden = YES;
}
return _vipImg;
}
- (UILabel *)askNameLabel {
if (!_askNameLabel) {
_askNameLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_askNameLabel.textColor = [UIColor colorWithHexString:BLUECOLOR];
_askNameLabel.font = appFont(15, NO);
_askNameLabel.textAlignment = NSTextAlignmentLeft;
_askNameLabel.backgroundColor = [UIColor clearColor];
}
return _askNameLabel;
}
-(UIButton *)askNameButton{
if (!_askNameButton) {
_askNameButton = [UIButton buttonWithType:UIButtonTypeCustom];
_askNameButton.backgroundColor = [UIColor clearColor];
[_askNameButton addTarget:self action:@selector(headBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
}
return _askNameButton;
}
- (RTLabel*)askContentLabel{
if (!_askContentLabel) {
_askContentLabel = [[RTLabel alloc]initWithFrame:CGRectMake(0, 0, tableWidht, 0)];
_askContentLabel.textColor = [UIColor colorWithHexString:TextBlack];
_askContentLabel.textAlignment = RTTextAlignmentLeft;
_askContentLabel.lineBreakMode = RTTextLineBreakModeWordWrapping;
_askContentLabel.lineSpacing = 10;
_askContentLabel.backgroundColor = [UIColor clearColor];
_askContentLabel.font = appFont(interactionFontSize, NO);//【需求变更】话题详情页问答列表的文字字号调整(bug:4445)
}
return _askContentLabel;
}
- (UILabel*)timeLabel {
if (!_timeLabel) {
_timeLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_timeLabel.textColor = [UIColor colorWithHexString:TextGray];
_timeLabel.font = appFont(11, NO);
_timeLabel.backgroundColor = [UIColor clearColor];
}
return _timeLabel;
}
- (UILabel*)answerLabel {
if (!_answerLabel) {
_answerLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_answerLabel.backgroundColor = [UIColor clearColor];
_answerLabel.textColor = [UIColor colorWithHexString:LINECOLOR];
_answerLabel.font = appFont(11, NO);
_answerLabel.layer.borderColor = [UIColor colorWithHexString:LINECOLOR].CGColor;
_answerLabel.layer.borderWidth = 1;
_answerLabel.layer.cornerRadius = 2;
_answerLabel.textAlignment = NSTextAlignmentCenter;
_answerLabel.backgroundColor = [UIColor clearColor];
}
return _answerLabel;
}
-(void)headBtnEvent:(UIButton *) btn{
if ([self.topicAskCellDelegate respondsToSelector:@selector(topicToOther:)]) {
[self.topicAskCellDelegate topicToOther:self.commentBO];
}
}
- (void)layoutSubviews {
[super layoutSubviews];
self.backView.frame = CGRectMake(padding, 0, tableWidht, CGRectGetHeight(self.contentView.bounds));
self.headPicImgView.frame = CGRectMake(0, 20, 35, 35);
self.headBtn.frame = self.headPicImgView.frame;
self.vipImg.center = CGPointMake(self.headPicImgView.center.x+15, self.headPicImgView.center.y+12);
self.askNameLabel.frame = CGRectMake(CGRectGetMaxX(self.headPicImgView.frame)+25/2,
CGRectGetMinY(self.headPicImgView.frame),
500,
20);
CGFloat nameWidth = widthForString(self.askNameLabel.text, self.askNameLabel.font, 30, self.askNameLabel.lineBreakMode);
self.askNameButton.frame = CGRectMake(CGRectGetMinX(self.askNameLabel.frame)-5, CGRectGetMinY(self.askNameLabel.frame)-5, nameWidth+10, 30);
self.timeLabel.frame = CGRectMake(CGRectGetMinX(self.askNameLabel.frame),
CGRectGetMaxY(self.askNameLabel.frame),
100,
16);
self.askContentLabel.frame = CGRectMake(CGRectGetMinX(self.headPicImgView.frame),
CGRectGetMaxY(self.headPicImgView.frame)+10,
tableWidht,
askContentHeight);
self.lineView.frame = CGRectMake(0, CGRectGetHeight(self.backView.bounds)-1, tableWidht, 1);
self.dashedLineView.frame = CGRectMake(0, CGRectGetHeight(self.backView.bounds)-1, tableWidht, 1);
if (!self.commentBO.isAnswer || [self.commentBO.isAnswer intValue] == 0) {
self.answerLabel.frame = CGRectMake(CGRectGetWidth(self.backView.bounds)-40,
CGRectGetMinY(self.headPicImgView.frame),
40,
20);
}else {
self.answerLabel.frame = CGRectMake(CGRectGetWidth(self.backView.bounds)-94/2,
CGRectGetMinY(self.headPicImgView.frame),
94/2,
20);
}
self.answerNumLabel.frame = CGRectMake(CGRectGetMaxX(self.askContentLabel.frame)-70,
CGRectGetMinY(self.askContentLabel.frame)-30,
70,
20);
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
|