I\'ve followed the instructions here and succesfully set up a UITextField that gets updated with a UIDatePicker. However the cursor in the UITextField is blinking, which see
I found this solution to be the easiest to implement.
Make sure you define UITextFieldDelegate in your .h file:
.... UIViewController <UITextFieldDelegate>
In your .m file, add this to the method you call fo the date picker:
[yourTextField resignFirstResponder];
This will prevent the textfield from blinking.
What I did was to overlay another UITextField on top of the one whose cursor I wanted to hide. Then in the delegate method textFieldShouldBeginEditing I set the other textField to become first responder and returned NO.
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if (textField.tag==TAG_OF_DUMMY_TEXTFIELD) {
[otherField becomeFirstResponder];
return NO;
}
return YES;
}
And then in the method the date picker calls:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@YOUR_DATE_FORMAT];
dummyField.text = [dateFormatter stringFromDate:datePicker.date];
In Interface Builder otherField (the one with the datePicker input view) is behind dummyField (the one that hides the cursor).
Subclass UITextfield and Override the - (CGRect)caretRectForPosition:(UITextPosition *)position
method and return CGRectZero
.
- (CGRect)caretRectForPosition:(UITextPosition *)position {
return CGRectZero;
}
Not the best solution, but you could also set the Opacity of the tint color to 0%.