AIDatePickerController
AIDatePickerController copied to clipboard
How it works with UITextField?
I want to implement this date picker with UITextField. But I can set this date picker as InputView of UITextfield. Please Help me out.
I also did this, but working properly.
[txtBirthdate addTarget:self action:@selector(openDatePicker:) forControlEvents:UIControlEventEditingDidBegin];
[txtBirthdate addTarget:self action:@selector(openDatePicker:) forControlEvents:UIControlEventEditingChanged];
`-(void)openDatePicker:(UITextField *)textField { [txtBirthdate resignFirstResponder]; __weak ProfileViewController *weakSelf = self;
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd-MM-yyyy"];
NSDate *date = [dateFormatter dateFromString:@"24-02-1955"];
// Create an instance of the picker
AIDatePickerController *datePickerViewController = [AIDatePickerController pickerWithDate:date selectedBlock:^(NSDate *selectedDate) {
NSDateFormatter* df = [[NSDateFormatter alloc]init];
df.dateFormat = @"dd-MMMM-yyyy";
NSString* dateString = [df stringFromDate:selectedDate];
txtBirthdate.text = dateString;
df.dateFormat = @"Y-M-d";
NSString* dtString = [df stringFromDate:selectedDate];
selectedDateString = dtString;
[txtBirthdate resignFirstResponder];
__strong ProfileViewController *strongSelf = weakSelf;
[strongSelf dismissViewControllerAnimated:YES completion:nil];
} cancelBlock:^{
// Do what you want when the user pressed the cancel button.
[txtBirthdate resignFirstResponder];
__strong ProfileViewController *strongSelf = weakSelf;
[strongSelf dismissViewControllerAnimated:YES completion:nil];
}];
// Present it
[self presentViewController:datePickerViewController animated:YES completion:nil];
} `