// // TimeBar.m // jiaPeiC // // Created by apple on 16/6/14. // Copyright © 2016年 JCZ. All rights reserved. // #import "TimeBar.h" #import "DateView.h" @implementation TimeBar -(id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; 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 = frame.size.width - 46; btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(x, 7, 26, 26); [btn setImage:[UIImage imageNamed:@"garbage.png"] forState:UIControlStateNormal]; [btn target:self Tag:3]; [self addSubview:btn]; } return self; } -(void)showWithRemove:(MyBlockType)remove { removeBlock = remove; } -(void)finishEndTime:(MyBlockType)endTimeB { endTimeBlock = endTimeB; } -(void)btnClick:(UIButton *)sender { if (sender.tag == 3) { if (removeBlock) { removeBlock(_timeTag); } 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]; if (endTimeBlock) { endTimeBlock(_timeTag); } } }]; } -(void)setBeginAndEndTimeWithBeginTime:(NSString *)beginString EndTime:(NSString *)endString { _beginTime = beginString; _endTime = endString; [beginBtn setTitle:beginString forState:UIControlStateNormal]; [endBtn setTitle:endString forState:UIControlStateNormal]; } @end