// // messageFocusCell.m // ThePaperHD // // Created by YoungLee on 15/7/31. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "messageFocusCell.h" @interface messageFocusCell(){ CGFloat askNumWidth; CGFloat askNameHeight; CGFloat askContentHeight; } @property(nonatomic, strong)UILabel *markLabel; @property(nonatomic, strong)RTLabel *askNumsLabel; @property(nonatomic, strong)UILabel *askNameLabel; @property(nonatomic, strong)RTLabel *askContentLabel; @end @implementation messageFocusCell @synthesize commentBO = _commentBO; @synthesize isHaveMenu = _isHaveMenu; @synthesize delegate; //需要呼出自定义菜单 - (BOOL)canBecomeFirstResponder{ [super canBecomeFirstResponder]; return YES; } - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.backgroundColor = [UIColor colorWithHexString:CardBackGroundColor]; self.selectionStyle = UITableViewCellSelectionStyleNone; self.clipsToBounds = YES; [self.contentView addSubview:self.askNameLabel]; [self.contentView addSubview:self.askContentLabel]; [self.contentView addSubview:self.askNumsLabel]; [self.contentView addSubview:self.markLabel]; } return self; } - (void)awakeFromNib { // Initialization code } - (UILabel*)askNameLabel { if (!_askNameLabel) { _askNameLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _askNameLabel.textColor = [UIColor colorWithHexString:BLUECOLOR]; _askNameLabel.font = appFont(15, NO); _askNameLabel.backgroundColor = [UIColor clearColor]; _askNameLabel.textAlignment = NSTextAlignmentLeft; } return _askNameLabel; } - (RTLabel*)askContentLabel { if (!_askContentLabel) { _askContentLabel = [[RTLabel alloc]initWithFrame:CGRectZero]; _askContentLabel.textColor = [UIColor colorWithHexString:TextBlack]; _askContentLabel.textAlignment = RTTextAlignmentLeft; _askContentLabel.lineBreakMode = NSLineBreakByWordWrapping; _askContentLabel.lineSpacing = 10; _askContentLabel.font = appFont(interactionFontSize, NO); } return _askContentLabel; } - (UILabel*)markLabel { if (!_markLabel) { _markLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _markLabel.backgroundColor = [UIColor colorWithHexString:@"0xc32128"]; _markLabel.layer.cornerRadius = 11/2; _markLabel.clipsToBounds = YES; _markLabel.textAlignment = NSTextAlignmentCenter; _markLabel.textColor = [UIColor whiteColor]; _markLabel.font = appFont(7, NO); _markLabel.hidden = YES; } return _markLabel; } -(RTLabel *)askNumsLabel{ if (!_askNumsLabel) { _askNumsLabel = [[RTLabel alloc]initWithFrame:CGRectZero]; _askNumsLabel.font = appFont(11, NO); _askNumsLabel.backgroundColor = [UIColor clearColor]; _askNumsLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; _askNumsLabel.textAlignment = RTTextAlignmentRight; _askNumsLabel.lineSpacing = 10; _askNumsLabel.lineBreakMode = RTTextLineBreakModeWordWrapping; } return _askNumsLabel; } - (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; if([user.userId intValue] == [[TPUserDefault instance].userBO.userId intValue]){ nameStr = @"我:"; }else{ nameStr = user.sname?[NSString stringWithFormat:@"%@:",user.sname]:@""; } // NSString *nameStr = user.sname?[NSString stringWithFormat:@"%@:",user.sname]:@""; askNameHeight = heightForString(nameStr, self.askNameLabel.font, 400, self.askNameLabel.lineBreakMode); // NSString *answerNumStr = data.answerNums?[NSString stringWithFormat:@"(%@个回答)",data.answerNums]:@""; NSString *answerNumStr = data.answerNums?[NSString stringWithFormat:@"(%@个回答)",data.answerNums]:@""; askContentHeight = returnTextHeightWithRTLabel(data.content, messagePopSize.width-30, appFont(15, NO),10); askNumWidth = widthForString(answerNumStr, self.askNumsLabel.font, askNameHeight, self.askNumsLabel.lineSpacing); NSString *newNum = data.unNums; dispatch_async(dispatch_get_main_queue(), ^{ self.askNameLabel.text = nameStr; self.askNumsLabel.text = answerNumStr; self.askContentLabel.text = data.content; if ([newNum intValue] >0 ) { if ([newNum intValue] > 9) { self.markLabel.text = @"9+"; }else{ self.markLabel.text = newNum; } self.markLabel.hidden = NO; }else { self.markLabel.hidden = YES; self.markLabel.text = @"0"; } [self layoutSubviews]; }); }); } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } -(void)layoutSubviews{ [super layoutSubviews]; if (self.isEditing) { [self sendSubviewToBack:self.contentView]; } self.askNameLabel.frame = CGRectMake(15,5, widthForString(self.askNameLabel.text, self.askNameLabel.font, askNameHeight, self.askNameLabel.lineBreakMode), askNameHeight); self.askNumsLabel.frame = CGRectMake(messagePopSize.width-15-askNumWidth, CGRectGetMinY(self.askNameLabel.frame), askNumWidth, CGRectGetHeight(self.askNameLabel.frame)); self.askContentLabel.frame = CGRectMake(CGRectGetMinX(self.askNameLabel.frame), CGRectGetMaxY(self.askNameLabel.frame)+10, messagePopSize.width-30, askContentHeight); self.markLabel.frame = CGRectMake(CGRectGetMaxX(self.askNumsLabel.frame)-5, CGRectGetMinY(self.askNumsLabel.frame)-5, 11, 11); for (UIView *subview in self.subviews) { for (UIView *subview2 in subview.subviews) { if ([NSStringFromClass([subview2 class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]) { // move delete confirmation view [subview bringSubviewToFront:subview2]; } } } } @end