根据label的内容返回自定义cell的高度

#import "hotmessagecell.h"

#import <Masonry.h>

@implementation hotmessagecell

+(instancetype)cellWithTableView:(UITableView *)tableView{

 static NSString *ID = @"hotmessagecell";

 id cell = [tableView dequeueReusableCellWithIdentifier:ID];

 if (cell==nil) {

  cell = [[self alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];

 }

 return cell;

}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

 if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

  self.selectionStyle = UITableViewCellSelectionStyleNone;

  _headview = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"xiao"]];

  _headview.frame = CGRectMake(10, 10, 40, 40);

  [self addSubview:_headview];


  float a =CGRectGetMaxY(_headview.frame);

  float headviewb = CGRectGetMaxX(_headview.frame);

  

//  float width = [UIScreen mainScreen].bounds.size.width;

//  CGSize boundSize = CGSizeMake(width-60, CGFLOAT_MAX);

  

  _contentLabel = [[UILabel alloc]init];

  _contentLabel.text = @"这儿用到了一个NSString的Cagetory方法:这儿用到了一个NSString的Cagetory方法:这儿用到了一个NSString的Cagetory方法:这儿用到了一个NSString的Cagetory方法";

  _contentLabel.textColor = [UIColor blackColor];

  _contentLabel.backgroundColor = [UIColor greenColor];

  _contentLabel.numberOfLines = 0;

  CGFloat mainwidth = [UIScreen mainScreen].bounds.size.width;

  

  NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];

  paragraph.alignmentNSLineBreakByWordWrapping;

  

  NSDictionary *atrribute = @{NSFontAttributeName:[UIFont systemFontOfSize:13],NSParagraphStyleAttributeName:paragraph};

  //CGSize equiredsize = [_contentLabel.text sizeWithFont:[UIFont systemFontOfSize:16] constrainedToSize:boundSize lineBreakMode:NSLineBreakByClipping];

  

  CGSize equiredsize = [_contentLabel.text boundingRectWithSize:CGSizeMake(100, 0) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:atrribute context:nil].size;

  

  CGRect rect = self.frame;

  rect.size.height = equiredsize.height +100;

  _contentLabel.frame = CGRectMake(headviewb +10, a,mainwidth-40-headviewb-10, equiredsize.height);

  [self addSubview:_contentLabel];

  [_contentLabel sizeToFit];

  CGFloat _contenth = CGRectGetMaxY(_contentLabel.frame);

  self.frame = CGRectMake(0, 0, self.frame.size.width, _contenth +10+10+headviewb);

  

  

  _huifuview = [[UIView alloc]init];

  _huifuview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Dialog-box"]];

  _huifuview.frame = CGRectMake(headviewb +10, _contenth, _contentLabel.frame.size.width-40, 35);

  [self addSubview:_huifuview];

  

  

  self.cellheight = _contenth +50;

  

 }

 return self;

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值