// // CommentCell.m // jiaPeiC // // Created by apple on 16/3/21. // Copyright © 2016年 JCZ. All rights reserved. // #import "CommentCell.h" #import "UIImageView+WebCache.h" @implementation CommentCell - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { UIImageView* iv = [[UIImageView alloc] init]; iv.layer.masksToBounds = YES; iv.contentMode = UIViewContentModeCenter; [iv setContentMode:UIViewContentModeScaleAspectFit]; [iv boardWid:1.5 Color:defGreen]; [self.contentView addSubview:iv]; headImg = iv; UILabel* lb; lb = [[UILabel alloc] init]; [lb setTextColor:titleColor]; [lb setFont:[UIFont scaleSize:Font16]]; [self.contentView addSubview:lb]; nameLabel = lb; lb = [[UILabel alloc] init]; [lb setTextColor:contentTextColor]; [lb setFont:[UIFont scaleSize:Font14]]; lb.numberOfLines = 0; [self.contentView addSubview:lb]; contentLabel = lb; lb = [[UILabel alloc] init]; [lb setTextColor:contentTextColor]; [lb setFont:[UIFont scaleSize:Font14]]; [self.contentView addSubview:lb]; dateLabel = lb; } [self setSelectionStyle:UITableViewCellSelectionStyleNone]; return self; } -(void)setDict:(NSDictionary *)dict { _dict = dict; NSString *path = dict[@"HEADIMG"]; if (!path) { path = @""; } [headImg sd_setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:[NSString stringWithFormat:@"portrait%d.png",arc4random()%10 + 1]]]; [nameLabel setText:dict[@"NAME"]]; [contentLabel setText:dict[@"PJCONTENT"]]; NSString* str = dict[@"PJSJ"]; if (str && str.length >11) { [dateLabel setText:[str substringToIndex:11]]; }else{ [dateLabel setText:str]; } } -(void)layoutSubviews { [super layoutSubviews]; CGFloat aWid = self.width; CGFloat x,w,h,y,bd; x = 8; w = h = 62; y = bd = 10; [headImg setFrame:CGRectMake(x, y, w, h)]; headImg.layer.cornerRadius = h/2.0; y += bd; x += w + bd; h = 25; [nameLabel setFrame:CGRectMake(x, y, 200, h)]; y = y+h; h = 25; [dateLabel setFrame:CGRectMake(x, y, 200, h)]; y += h + bd; w = aWid - x - bd; h = [contentLabel.text heightForWid:w Font:Font14]; if (h < 30.0) { h = 30; } [contentLabel setFrame:CGRectMake(x, y, w, h)]; //固定高度90 最小高度120 } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end