// // TimeBarCell.m // jiaPeiC // // Created by apple on 16/6/16. // Copyright © 2016年 JCZ. All rights reserved. // #import "TimeBarCell.h" #import "DateView.h" @implementation TimeBarCell - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { //初始值 _beginTime = @"开始时间"; _endTime = @"结束时间"; CGFloat x = 20; UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(x, 5, 80, 30); btn.backgroundColor = lineColor; [btn setTitle:@"开始时间" textColor:contentTextColor font:Font16 fotState:UIControlStateNormal]; [btn borderColor:lineColor width:1 cornorRadios:5]; [btn target:self Tag:1]; [self addSubview:btn]; beginBtn = btn; [btn addViewWithRect:CGRectMake(x + 82, 20, 16, 1)]; x += 100; btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(x, 5, 80, 30); btn.backgroundColor = lineColor; [btn setTitle:@"结束时间" textColor:contentTextColor font:Font16 fotState:UIControlStateNormal]; [btn borderColor:lineColor width:1 cornorRadios:5]; [btn target:self Tag:2]; [self addSubview:btn]; endBtn = btn; x = kSize.width - 46; btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(x, 7, 26, 26); [btn setImage:[UIImage imageNamed:@"cancel"] forState:UIControlStateNormal]; [btn target:self Tag:3]; [self addSubview:btn]; } return self; } -(void)showWithRemove:(MyBlockType)remove { removeBlock = remove; } -(void)btnClick:(UIButton *)sender { if (sender.tag == 3) { if (removeBlock) { removeBlock(_timeTag); } [self removeFromSuperview]; return; } DateView* dv = [[DateView alloc] init]; [dv setStyle:1]; [dv showWithComplete:^(NSString *time) { if (sender.tag == 1) { _beginTime = time; [beginBtn setTitle:time forState:UIControlStateNormal]; } if (sender.tag == 2) { _endTime = time; [endBtn setTitle:time forState:UIControlStateNormal]; } }]; } -(void)setBeginAndEndTimeWithBeginTime:(NSString *)beginString EndTime:(NSString *)endString { _beginTime = beginString; _endTime = endString; [beginBtn setTitle:beginString forState:UIControlStateNormal]; [endBtn setTitle:endString forState:UIControlStateNormal]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; } @end