// // PlanCell.m // jiaPeiC // // Created by apple on 15/12/18. // Copyright © 2015年 JCZ. All rights reserved. // #import "PlanCell.h" @interface PlanCell() @end @implementation PlanCell - (void)awakeFromNib { [super awakeFromNib]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; } -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { UILabel* label;UIImageView* iv;UIButton* btn; label = [UILabel new]; [self addSubview:label]; lblDate = label; label = [UILabel new]; [self addSubview:label]; lblName = label; label = [UILabel new]; [self addSubview:label]; lblNum = label; label = [UILabel new]; [self addSubview:label]; titNum = label; label = [UILabel new]; [self addSubview:label]; titDate = label; label = [UILabel new]; [self addSubview:label]; titCount = label; label = [UILabel new]; [self addSubview:label]; countLabel = label; iv = [UIImageView new]; [self addSubview:iv]; imgDate = iv; iv = [UIImageView new]; [self addSubview:iv]; imgNum = iv; btn = [UIButton new]; [self addSubview:btn]; btnScan = btn; // [imgNum imageName:@"send_time_icon.png"]; [imgNum setImage:[UIImage imageNamed:@"send_time_icon.png"]]; [imgDate setImage:[UIImage imageNamed:@"send_people_num_icon.png"]]; // [imgDate imageName:@"send_people_num_icon.png"]; [titNum setFont:[UIFont scaleSize:Font16]]; [titDate setFont:[UIFont scaleSize:Font16]]; [self.textLabel setFont:[UIFont scaleSize:Font16]]; [self.detailTextLabel setFont:[UIFont scaleSize:Font16]]; [titCount setFont:[UIFont scaleSize:Font16]]; [countLabel setFont:[UIFont scaleSize:Font18]]; [lblNum setFont:[UIFont scaleSize:Font18]]; [lblDate setFont:[UIFont scaleSize:Font18]]; lblDate.numberOfLines = 0; [btnScan setTitleColor:defGreen forState:UIControlStateNormal]; } return self; } +(PlanCell*)cellForTabelView:(UITableView*)tableView { PlanCell* cell = [tableView dequeueReusableCellWithIdentifier:@"PlanCell"]; if (!cell) { cell = [[PlanCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"PlanCell"]; } return cell; } -(void)setModel:(NSDictionary *)model { _model = model; [self.textLabel setText:model[@"title"]]; [self.detailTextLabel setText:model[@"content"]]; [lblName setText:model[@"userName"]]; [lblNum setText:model[@"num"]]; [lblDate setText:[NSString stringWithFormat:@"%@\n%@",model[@"taskTime"],model[@"times"]]]; [countLabel setText:model[@"havNum"]]; [titDate setText:@"预约时间:"]; [titNum setText:@"可预约人数:"]; [titCount setText:@"已预约人数:"]; [btnScan setTitle:@"查看预约" forState:UIControlStateNormal]; } -(void)layoutSubviews { [super layoutSubviews]; CGFloat wid = self.width; // CGFloat hei = self.height; // SetRandomColor(btnScan); // SetRandomColor(self.textLabel); // SetRandomColor(self.detailTextLabel); CGFloat x,y,w,h,bd; bd = 20; h = w = 80; x = wid - w; y = 0; [lblName setFrame:CGRectMake(x, y, w, h)]; y = self.height - h; w *= 1.3; x = wid - w; [btnScan setFrame:CGRectMake(x, y, w, h)]; [btnScan target:self]; y = 0; x = bd; h = 35; w = kSize.width - bd - w; [self.textLabel setFrame:CGRectMake(x, y, w, h)]; y += h-10; [self.detailTextLabel setFrame:CGRectMake(x, y, w, h)]; y += h ; w = h = 40; [imgDate setFrame:CGRectMake(x, y, w, h)]; x += w +10; w = [titNum.text sizeForFont:Font16].width ; [titNum setFrame:CGRectMake(x, y - 5, w, 25)]; [titCount setFrame:CGRectMake(x, y + 20, w, 25)]; x += w +10; w = 100; [lblNum setFrame:CGRectMake(x, y - 3, w, 25)]; [countLabel setFrame:CGRectMake(x, y + 20, w, 25)]; x = bd; y += h ; w = h = 40; [imgNum setFrame:CGRectMake(x, y, w, h)]; x += w +10; w = [titDate.text sizeForFont:Font16].width ; [titDate setFrame:CGRectMake(x, y - 2, w, h)]; x += w +10; w = 200; [lblDate setFrame:CGRectMake(x, y - 5, w, h+20)]; // for (UIView* v in self.subviews) { // SetRandomColor(v); // } } -(void)click:(MyBlockType)block { clkBlock = block; } -(void)btnClick:(UIButton*)sender { if (clkBlock) { clkBlock(_model); } } -(void)setStyle:(int)style { _style = style; if (1 == style) { [btnScan setHidden:YES]; } } @end CGFloat PlanCellHeight() { return 150; }