StartTimeView.m 2.28 KB
Newer Older
陈俊俊's avatar
陈俊俊 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//
//  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;
}
陈俊俊's avatar
陈俊俊 committed
16
@property (nonatomic,strong)NSDate *currentDate;
陈俊俊's avatar
陈俊俊 committed
17 18 19 20 21 22 23
@end

@implementation StartTimeView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
陈俊俊's avatar
陈俊俊 committed
24 25 26 27
        [self bulidLayout];
    }
    return self;
}
陈俊俊's avatar
陈俊俊 committed
28
- (instancetype)initWithFrame:(CGRect)frame withDate:(NSDate *)currentDate
陈俊俊's avatar
陈俊俊 committed
29 30 31
{
    self = [super initWithFrame:frame];
    if (self) {
陈俊俊's avatar
陈俊俊 committed
32
        self.currentDate = currentDate;
陈俊俊's avatar
陈俊俊 committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
        [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];
陈俊俊's avatar
陈俊俊 committed
50 51
    _timePicker.date = self.currentDate;
    _timePicker.datePickerMode = UIDatePickerModeDate;
陈俊俊's avatar
陈俊俊 committed
52
    _timePicker.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"];
陈俊俊's avatar
陈俊俊 committed
53 54
//    // 设置最小时间段,防止用户的出现已过去的时间
//    _timePicker.minimumDate      = [NSDate date];
陈俊俊's avatar
陈俊俊 committed
55
    [_bgView addSubview:_timePicker];
陈俊俊's avatar
陈俊俊 committed
56
   
陈俊俊's avatar
陈俊俊 committed
57 58 59 60 61 62 63 64 65
}


- (void)okClick{
    [self.delegate okTimeView:_timePicker.date];
}
- (void)cancelClick{
    [self.delegate cancelTimeView];
}
66 67 68
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.delegate cancelTimeView];
}
陈俊俊's avatar
陈俊俊 committed
69
@end