I want to display a picker when the user clicks on a button I subclassed the UIButton and changed its inputview so that it is writable.
I followed this link http://
1) Create a subclass of a UIButton
.h
#import
@interface UIButtonAsFirstResponder : UIButton
@property (strong, nonatomic) UIView *inputView;
@property (strong, nonatomic) UIView *inputAccessoryView;
@end
.m
#import "UIButtonAsFirstResponder.h"
@implementation UIButtonAsFirstResponder
- (BOOL) canBecomeFirstResponder
{
return YES;
}
@end
2) Set inputView
(if needed also inputAccessoryView
) in your view controller (to your picker or any other custom view)
3) Create IBAction for your button in your view controller
- (IBAction)becom:(id)sender {
[sender becomeFirstResponder];
}
If you want to remove keyboard, call on your button:
[button resignFirstResponder];
or in view controller:
[self.view endEditing:YES];