Cell的高度

//.h

#import <UIKit/UIKit.h>


@protocolTCommentCellDelegate;

@interface TCommentCell :UITableViewCell

{

   UIImageView *_headView;

   UILabel *_titleLabel;

   UILabel *_commentLabel;

   UILabel *_timeLabel;

   UIButton *_replyButton;

    

   UILabel *_numberLabel;

    

    //cell背景

   UIImageView *_bgImgView;

    

    id <TCommentCellDelegate>_delegate;

}

@property (nonatomic,retain)UILabel *numberLabel;

@property (nonatomic,assign)id<TCommentCellDelegate>delegate;

@property (nonatomic,retain)UIButton *replayButton;


+ (CGFloat)heightOfCell:(BookComment *)bookComment;

+ (CGFloat)tableViewHigth:(NSArray *)modelList;


- (void)reloadData:(BookComment *)bookComment;

@end


@protocol TCommentCellDelegate <NSObject>


- (void)replayBtnClicked:(TCommentCell *)commentCell;

- (void)reloadData:(BookComment *)bookComment;


@end


//.m

- (void)reloadData:(BookComment *)bookComment;
- (void)reloadData:(BookComment *)bookComment;

#import "TCommentCell.h"

#import "UIImageView+WebCache.h"


#define TOP_Y 10

#define TOP_X 10

#define HEADVIEW_HEIGHT 50.0f

#define LABEL_HEIGHT 20.0f

#define CONTENT_WIDTH 200

#define FONT_SIZE 12

//空间竖直方向的间隔

#define GAP 5


@implementation TCommentCell


@synthesize numberLabel =_numberLabel;

@synthesize delegate =_delegate;

@synthesize replayButton =_replyButton;


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

   self = [superinitWithStyle:stylereuseIdentifier:reuseIdentifier];

   if (self) {

        

        UIImageView *view1 = [[UIImageViewalloc]initWithFrame:CGRectMake(TOP_Y,TOP_Y, HEADVIEW_HEIGHT, HEADVIEW_HEIGHT)];

        view1.backgroundColor =COLOR(224,224, 224);

        [selfaddSubview:view1];

        [view1release];

        

       UIImageView *view2 = [[UIImageViewalloc] initWithFrame:CGRectMake(1,1, HEADVIEW_HEIGHT-2,HEADVIEW_HEIGHT-2)];

        view2.backgroundColor = [UIColorwhiteColor];

        [view1addSubview:view2];

        [view2release];

        

       _headView = [[UIImageViewalloc] init];

        _headView.frame =CGRectMake(2,2,HEADVIEW_HEIGHT-4,HEADVIEW_HEIGHT-4);

        [view1addSubview:_headView];


        _replyButton = [UIButtonbuttonWithType:UIButtonTypeCustom];

       _replyButton.frame =CGRectMake(270,30, 42, 22);

        [_replyButtonsetTitleColor:[UIColorwhiteColor] forState:UIControlStateNormal];

        [_replyButtonsetBackgroundImage:[UIImageimageNamed:@"comment_sel"]forState:UIControlStateNormal];

        [_replyButtonsetBackgroundImage:[UIImageimageNamed:@"comment_sel"]forState:UIControlStateHighlighted];

        [_replyButtonaddTarget:selfaction:@selector(btnClicked:)forControlEvents:UIControlEventTouchUpInside];

        [selfaddSubview:_replyButton];

        

       _titleLabel = [[UILabelalloc] init];

        _titleLabel.backgroundColor = [UIColorclearColor];

       _titleLabel.font = [UIFontsystemFontOfSize:15];

       _titleLabel.textColor =_colorTxt2;

        _titleLabel.highlightedTextColor =_colorTxt2;

        _titleLabel.frame = CGRectMake(TOP_X+HEADVIEW_HEIGHT+GAP,TOP_Y, CONTENT_WIDTH, LABEL_HEIGHT);

        [selfaddSubview:_titleLabel];

        

       _commentLabel = [[UILabelalloc] init];

        _commentLabel.backgroundColor = [UIColorclearColor];

       _commentLabel.textColor =_colorTxt1;

        _commentLabel.highlightedTextColor =_colorTxt1;

       _commentLabel.font = [UIFontsystemFontOfSize:FONT_SIZE];

        [selfaddSubview:_commentLabel];

        

       _timeLabel = [[UILabelalloc] init];

        _timeLabel.backgroundColor = [UIColorclearColor];

       _timeLabel.textColor =_colorTxt2;

        _timeLabel.highlightedTextColor =_colorTxt2;

       _timeLabel.font = [UIFontsystemFontOfSize:FONT_SIZE];

        [selfaddSubview:_timeLabel];

        

       _numberLabel = [[UILabelalloc] init];

        _numberLabel.backgroundColor = [UIColorclearColor];

       _numberLabel.textColor = [UIColororangeColor];

        _numberLabel.highlightedTextColor = [UIColororangeColor];

        _numberLabel.textAlignment = UITextAlignmentRight;

       _numberLabel.font = [UIFontsystemFontOfSize:FONT_SIZE];

        [selfaddSubview:_numberLabel];

        [_numberLabelrelease];

        

        //cell 背景

       _bgImgView = [[UIImageViewalloc] init]; 

        _bgImgView.highlightedImage = [UIImageimageNamed:@"cell_list_selected_bg"];

        [selfaddSubview:_bgImgView];

        [selfsendSubviewToBack:_bgImgView];

        [_bgImgViewrelease];

     }

    

    returnself;

}


+ (CGFloat)heightOfCell:(BookComment *)bookComment

{

   CGFloat height =0;

    

    CGSize size = [bookComment.contentsizeWithFont:[UIFontsystemFontOfSize:FONT_SIZE]constrainedToSize:CGSizeMake(CONTENT_WIDTH,2000)lineBreakMode:UILineBreakModeCharacterWrap];

    height = TOP_Y +LABEL_HEIGHT +GAP + size.height +GAP + LABEL_HEIGHT + TOP_Y;

    

   return height;

}


+ (CGFloat)tableViewHigth:(NSArray *)modelList

{

   CGFloat h = 0;

   for (BookComment *commentin modelList) {

        h = h + [selfheightOfCell:comment];

    }

    

   return h;

}



- (void)reloadData:(BookComment *)bookComment

{

    [_headViewsetImageWithURL:[NSURLURLWithString:bookComment.logo]placeholderImage:[UIImageimageNamed:@"xitong"]];

    

    _titleLabel.text = bookComment.name;

    

    CGSize size = [bookComment.contentsizeWithFont:[UIFontsystemFontOfSize:FONT_SIZE]constrainedToSize:CGSizeMake(CONTENT_WIDTH,2000)lineBreakMode:UILineBreakModeCharacterWrap];

    

    _commentLabel.frame = CGRectMake(TOP_X +HEADVIEW_HEIGHT +GAP, TOP_Y + LABEL_HEIGHT +GAP, CONTENT_WIDTH, size.height);

    _commentLabel.numberOfLines =0;

   _commentLabel.text = bookComment.content;

    

    _timeLabel.frame = CGRectMake(TOP_X +HEADVIEW_HEIGHT +GAP, TOP_Y + LABEL_HEIGHT +GAP + size.height +GAP, 180,LABEL_HEIGHT);

    _timeLabel.text = [SystemSupportdateTimeYMDHMS:bookComment.time];

    

    _numberLabel.frame = CGRectMake(TOP_X +HEADVIEW_HEIGHT +GAP + 190,TOP_Y + LABEL_HEIGHT + GAP + size.height +GAP, 60,LABEL_HEIGHT);

   _numberLabel.text = [NSStringstringWithFormat:@"(%@条回复)",bookComment.replyCount]; 

     

   _bgImgView.frame =CGRectMake(0,0, IPHONE_WIDTH, [TCommentCellheightOfCell:bookComment]);


}


#pragma mark - 回复按钮点击


- (void)btnClicked:(UIButton *)btn

{

   if ([self.delegaterespondsToSelector:@selector(replayBtnClicked:)]){

        [self.delegatereplayBtnClicked:self];

    }

}


- (void)dealloc

{

    [_headViewrelease];

    [_titleLabelrelease];

    [_commentLabelrelease];

    [_timeLabelrelease];

    

    [superdealloc];

}


@end




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值