You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.5 KiB

2 years ago
//
// showTimeCell.m
// b
//
// Created by kaidan on 2017/1/12.
// Copyright © 2017kaidan. All rights reserved.
//
#import "Masonry.h"
#import "showTimeCell.h"
#import "JGPicker.h"
@interface showTimeCell ()<JGPickerDelegate>
@property(nonatomic,strong)JGPicker* picker;
@property(nonatomic,strong)UIButton* clickBtn;
@property(nonatomic,strong)UILabel* lab;
@end
@implementation showTimeCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
-(UIButton *)clickBtn{
if (!_clickBtn) {
_clickBtn = [[UIButton alloc] init];
[_clickBtn setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
}
return _clickBtn;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self addSubViews];
}
return self;
}
-(void)addSubViews{
self.lab = [[UILabel alloc] init];
self.lab.text = @"";
self.lab.textAlignment = NSTextAlignmentLeft;
NSDate* date = [NSDate date];
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy年MM月dd日";
self.lab.text = [formatter stringFromDate:date];
self.textLabel.text = @"出生日期";
self.picker = [[JGPicker alloc] initWithFrame:[[UIScreen mainScreen] bounds] type:UIDatePickerModeDate andDelegate:self];
[self addSubview:self.clickBtn];
[self.clickBtn addSubview:self.lab];
[self.clickBtn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
[self.clickBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.height.equalTo(self);
make.width.mas_equalTo(self).multipliedBy(0.5);
make.left.mas_equalTo(self.mas_centerX);
}];
[self.lab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.height.equalTo(self.clickBtn);
make.right.equalTo(self.mas_right).offset(30);
}];
}
#pragma JGPickerDelegate
- (void)determinSelected:(NSDate *)date
{
// self.lab.text = [_picker stringFromDate:date];
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy年MM月dd日";
self.lab.text = [formatter stringFromDate:date];
NSLog(@"最终选择了:%@",[_picker stringFromDate:date]);
}
-(void)click{
[self.picker show];
}
-(NSString *)dateStr{
return self.lab.text;
}
@end