我不确定它是否能够在点击时在UITextField下动态添加DatePicker。如果可能,请帮我展示示例代码。
答案 0 :(得分:1)
设置文字字段版本为 点击文字字段时的方法 当日期值更改时,此方法称为 我希望它会对你有所帮助! :) - (void)viewDidLoad {
[super viewDidLoad];
[textField addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventEditingDidBegin];
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
return NO;
}
-(IBAction)clicked:(id)sender
{
[sender resignFirstResponder];
picker1 = [[UIDatePicker alloc] initWithFrame:CGRectMake(textField.frame.origin.x-40, textField.frame.origin.y+textField.frame.size.height, textField.frame.size.width, 200)];
[picker1 setDatePickerMode:UIDatePickerModeDate];
picker1.backgroundColor = [UIColor whiteColor];
[picker1 addTarget:self action:@selector(startDateSelected:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:picker1];
}
-(IBAction)startDateSelected:(id)sender
{
NSLog(@"%@",picker1.date);
[textField setText:[NSString stringWithFormat:@"%@",picker1.date
]];
}