热更新demo

commentCell.m 7.0KB

    // // commentCell.m // ThePaperDemo // // Created by scar1900 on 14-9-26. // Copyright (c) 2014年 scar1900. All rights reserved. // #import "commentCell.h" #import "commentOkButton.h" @interface commentCell() @property(nonatomic, strong)UIView *lineView; @property(nonatomic, strong)UIView *backView; @property(nonatomic, strong)UILabel *commentNameLabel; @property(nonatomic, strong)RTLabel *commentContentLabel; @property(nonatomic, strong)commentOkButton *OkButton; @property(nonatomic, strong)UIImageView *commentBack; @property(nonatomic, strong)UILabel *quoNameLable; //楼层用户名 @property(nonatomic, strong)UILabel *quoContentLabel; //楼层内容 @end @implementation commentCell @synthesize commentBO = _commentBO; - (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.lineView]; [self.backView addSubview:self.commentNameLabel]; [self.backView addSubview:self.commentContentLabel]; [self.backView addSubview:self.OkButton]; }return self; } - (void)setCommentBO:(commentObjectVO *)data { _commentBO = data; self.commentNameLabel.text = data.userName?[NSString stringWithFormat:@"%@:",data.userName]:@""; self.commentContentLabel.text = data.content; self.OkButton.text = data.praiseTimes; self.OkButton.selected = [data.isAttented boolValue]; if (data.quoteInfo && data.quoteInfo.allKeys.count>0) { NSDictionary *dic = data.quoteInfo; commentObjectVO *quoBO = setJsonDicToDataModel(dic, [commentObjectVO class]); [self.backView addSubview:self.commentBack]; self.commentBack.hidden = NO; [self.commentBack addSubview:self.quoNameLable]; self.quoNameLable.hidden = NO; self.quoNameLable.text =[NSString stringWithFormat:@"%@:",quoBO.userName]; [self.commentBack addSubview:self.quoContentLabel]; self.quoContentLabel.hidden = NO; self.quoContentLabel.text = quoBO.content; }else { self.commentBack.hidden = YES; [self.commentBack removeFromSuperview]; self.quoNameLable.hidden = YES; [self.quoNameLable removeFromSuperview]; self.quoContentLabel.hidden = YES; [self.quoContentLabel removeFromSuperview]; } } - (UIView*)backView { if (!_backView) { _backView = [[UIView alloc]initWithFrame:CGRectZero]; _backView.backgroundColor = [UIColor whiteColor]; } return _backView; } - (UIView*)lineView { if (!_lineView) { _lineView = [[UIView alloc]initWithFrame:CGRectZero]; _lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _lineView; } - (UILabel*)commentNameLabel { if (!_commentNameLabel) { _commentNameLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _commentNameLabel.textColor = [UIColor colorWithHexString:BLUECOLOR]; _commentNameLabel.textAlignment = NSTextAlignmentLeft; } _commentNameLabel.font = appFont(11, NO); return _commentNameLabel; } - (RTLabel*)commentContentLabel { if (!_commentContentLabel) { _commentContentLabel = [[RTLabel alloc]initWithFrame:CGRectZero]; _commentContentLabel.textColor = [UIColor colorWithHexString:TextGray]; _commentContentLabel.textAlignment = RTTextAlignmentLeft; _commentContentLabel.lineBreakMode = RTTextLineBreakModeWordWrapping; _commentContentLabel.lineSpacing = 7; } _commentContentLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO); return _commentContentLabel; } - (UIImageView*)commentBack { if (!_commentBack) { _commentBack = [[UIImageView alloc]initWithImage:Image(@"detailPage/commentBack.png")]; _commentBack.userInteractionEnabled = YES; _commentBack.hidden = YES; } return _commentBack; } - (UILabel*)quoNameLable { if (!_quoNameLable) { _quoNameLable = [[UILabel alloc]initWithFrame:CGRectZero]; _quoNameLable.textColor = [UIColor colorWithHexString:LIGHTGRAY]; _quoNameLable.textAlignment = NSTextAlignmentLeft; _quoNameLable.hidden = YES; } _quoNameLable.font = appFont(13,NO); return _quoNameLable; } - (UILabel*)quoContentLabel { if (!_quoContentLabel) { _quoContentLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _quoContentLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; _quoContentLabel.textAlignment = NSTextAlignmentLeft; _quoContentLabel.numberOfLines = 2; _quoContentLabel.lineBreakMode = NSLineBreakByTruncatingTail; } _quoContentLabel.font = appFont(13,NO); return _quoContentLabel; } - (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; } - (void)commentOK:(UIButton*)btn { btn.selected = !btn.selected; } - (void)layoutSubviews { [super layoutSubviews]; self.backView.frame = CGRectMake(10, 10, CGRectGetWidth(self.bounds)-20, CGRectGetHeight(self.bounds)-10); self.lineView.frame = CGRectMake(0, CGRectGetHeight(self.backView.bounds)-1, CGRectGetWidth(self.backView.bounds), 1); self.commentNameLabel.frame = CGRectMake(35, 7, CGRectGetWidth(self.backView.bounds)-20, 13); CGFloat contentHeight = 0; if (self.commentBO.quoteInfo && self.commentBO.quoteInfo.allKeys.count >0) { contentHeight = CGRectGetHeight(self.backView.bounds) - CGRectGetMaxY(self.commentNameLabel.frame)-7-146/2-20; }else contentHeight = CGRectGetHeight(self.backView.bounds) - CGRectGetMaxY(self.commentNameLabel.frame)-7-15/2; self.commentContentLabel.frame = CGRectMake(CGRectGetMinX(self.commentNameLabel.frame), CGRectGetMaxY(self.commentNameLabel.frame)+7, 490/2, contentHeight); self.OkButton.frame = CGRectMake(2, 7, 30, 35); if (!self.commentBack.hidden) { CGSize imageBackSize = self.commentBack.image.size; self.commentBack.frame =CGRectMake(CGRectGetMinX(self.commentContentLabel.frame), CGRectGetMaxY(self.commentContentLabel.frame)+15/2, imageBackSize.width, imageBackSize.height); self.quoNameLable.frame = CGRectMake(10, 20, CGRectGetWidth(self.commentBack.frame)-15, 25/2); self.quoContentLabel.frame = CGRectMake(10, CGRectGetMaxY(self.quoNameLable.frame)+2, CGRectGetWidth(self.quoNameLable.frame), 35); } } @end