1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// StartTimeView.m
// XFFurit
//
// Created by陈俊俊 on 15/8/5.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "StartTimeView.h"
#define DateViewHeight 246
@interface StartTimeView ()
{
UIView *_bgView;
UIDatePicker *_timePicker;
}
@property (nonatomic,strong)NSDate *currentDate;
@end
@implementation StartTimeView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self bulidLayout];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame withDate:(NSDate *)currentDate
{
self = [super initWithFrame:frame];
if (self) {
self.currentDate = currentDate;
[self bulidLayout];
}
return self;
}
- (void)bulidLayout{
_bgView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height - DateViewHeight, ScreenSize.width, DateViewHeight)];
_bgView.backgroundColor = RGBA(239, 239, 239 ,1);
[self addSubview:_bgView];
UIButton *okBtn = [IBTCustomButtom creatButtonWithFrame:CGRectMake(ScreenSize.width - 62, 0, 62, 28) target:self sel:@selector(okClick) tag:0 image:nil title:@"确定" titleColor:[UIColor blackColor] isCorner:NO corner:0 bgColor:RGBA(239, 239, 239 ,1)];
[_bgView addSubview:okBtn];
UIButton *cancelBtn = [IBTCustomButtom creatButtonWithFrame:CGRectMake(0, 0, 62, 28) target:self sel:@selector(cancelClick) tag:0 image:nil title:@"取消" titleColor:[UIColor blackColor] isCorner:NO corner:0 bgColor:RGBA(239, 239, 239 ,1)];
[_bgView addSubview:cancelBtn];
_timePicker= [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 30,ScreenSize.width, DateViewHeight - 30)];
_timePicker.backgroundColor = [UIColor whiteColor];
_timePicker.date = self.currentDate;
_timePicker.datePickerMode = UIDatePickerModeDate;
_timePicker.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"];
// // 设置最小时间段,防止用户的出现已过去的时间
// _timePicker.minimumDate = [NSDate date];
[_bgView addSubview:_timePicker];
}
- (void)okClick{
[self.delegate okTimeView:_timePicker.date];
}
- (void)cancelClick{
[self.delegate cancelTimeView];
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self.delegate cancelTimeView];
}
@end