EvaluateTableViewCell.h
#import
@interface EvaluateTableViewCell : UITableViewCell
@property (nonatomic,strong) UILabel *phoneLabel;
@property (nonatomic,strong) UILabel *timeLabel;
@property (nonatomic,strong) UILabel *descLabel;
@property (nonatomic,strong) UIView *intervalView;
//评价内容并且实现自动换行
-(void)setIntroductionText:(NSString*)text;
@end
EvaluateTableViewCell.m
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
//用户手机号
self.phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(7, 15, 100, 12)];
self.phoneLabel.font = FONT(12);
[self addSubview:self.phoneLabel];
//评价时间
self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(247 * (kScreenWidth / 320), 15, 72, 11)];
self.timeLabel.font = FONT(11);
self.timeLabel.textColor = [UIColor grayColor];
[self addSubview:self.timeLabel];
//分隔线
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(8, self.timeLabel.maxY + 14, kScreenWidth - 16, 1)];
lineView.backgroundColor = [UIColor blackColor];
[self addSubview:lineView];
//评价内容
self.descLabel = [[UILabel alloc] initWithFrame:CGRectMake(11, lineView.maxY+ 29, kScreenWidth - 22, 13)];
self.descLabel.font = FONT(12);
self.descLabel.numberOfLines = 0;
[self addSubview:self.descLabel];
//间隔
self.intervalView = [[UIView alloc] initWithFrame:CGRectMake(0, self.descLabel.maxY + 9, kScreenWidth, 2)];
self.intervalView.backgroundColor = [UIColor blackColor];
[self addSubview:self.intervalView];
}
return self;
}
//赋值 and 自动换行,计算出cell的高度
-(void)setIntroductionText:(NSString*)text{
//获得当前cell高度
CGRect frame = [self frame];
//文本赋值
self.descLabel.text = text;
//设置label的最大行数
CGSize size = CGSizeMake(300, 1000);
CGSize labelSize = [self.descLabel.text sizeWithFont:self.descLabel.font constrainedToSize:size lineBreakMode:NSLineBreakByClipping];
self.descLabel.frame = CGRectMake(self.descLabel.frame.origin.x, self.descLabel.frame.origin.y, labelSize.width, labelSize.height);
//计算出自适应的高度
frame.size.height = labelSize.height + 85;
self.frame = frame;
self.intervalView.frame = CGRectMake(0, self.descLabel.maxY + 9, kScreenWidth, 4);
}
|