#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.alignment = NSLineBreakByWordWrapping;
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;
}