I\'d like to Display UIDatePicker only when user the UITextField is Clicked. When the date is picked, it should be shown in the same UITextField.I want to implement UIDatePicker
Before going to this code, you need to just know about UIActionSheet
and You need to implement UIActionShetDelegate
and UITextFieldDelegate
In the textFieldDidBeginEditing
you need to show the action sheet as below:
-(void)textFieldDidBeginEditing:(UITextField *)sender
{
UIActionSheet *asheet = [[UIActionSheet alloc] initWithTitle:@"Select Date" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Select", nil];
[asheet showInView:[self.view superview]];
[asheet setFrame:CGRectMake(0, 117, 320, 383)];
}
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 320, 240)];
[pickerView setMinuteInterval:5];
[pickerView setTag: DatePickerTag];
[actionSheet addSubview:pickerView];
NSArray *subviews = [actionSheet subviews];
[[subviews objectAtIndex:SelectButtonIndex] setFrame:CGRectMake(20, 250, 280, 46)];
[[subviews objectAtIndex:CancelButtonIndex] setFrame:CGRectMake(20, 300, 280, 46)];
}