I would use a UILabel to allow users to select a date with UIDatePicker.
To do this, I created an UILabel subclass overwriting the inputView and the inputAccessoryVi
I know this is an old question but this might still be useful to someone.
There is another way to solve this - there is no need to complicate things with gesture recognizers...
GTPDateLabel.h
@interface GTPDateLabel : UILabel
@property (readonly, retain) UIView *inputView;
@end
GTPDateLabel.m
#import "GTPDateLabel.h"
@implementation GTPDateLabel
@synthesize inputView = _inputView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.userInteractionEnabled = YES;
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
self.userInteractionEnabled = YES;
}
return self;
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesEnded:touches withEvent:event];
[self becomeFirstResponder];
}
- (BOOL)canBecomeFirstResponder
{
return YES;
}
-(UIView *)inputView
{
if (!_inputView)
{
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
_inputView = datePicker;
}
return _inputView;
}
@end
Note that you should also set the delegate and in case of custom UIPicker also dataSource...