step1: Override the nib file and keyboard type–
// The designated initializer. Override to perform setup that is required before the view is loaded.
– (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
notes.keyboardType = UIKeyboardTypeAlphabet;
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
return self;
}
Step 2. Detect keyboard view and add a button to that view at specific position:-
– (void)keyboardWillShow:(NSNotification*)notification {
//The UIWindow that contains the keyboard view
UIWindow* tempWindow;
//Because we can’t get access to the UIKeyboard through the SDK we will just use UIView.
//UIKeyboard is a subclass of UIView anyways
UIView* keyboard;
//Check each window in our application
for(int c = 0; c < [[[UIApplication sharedApplication] windows] count]; c ++)
{
//Get a reference of the current window
tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:c];
//Get a reference of the current view
for(int i = 0; i < [tempWindow.subviews count]; i++)
{
keyboard = [tempWindow.subviews objectAtIndex:i];
if([[keyboard description] hasPrefix:@”<UIKeyboard”] == YES)
{
//Keyboard is now a UIView reference to the UIKeyboard we want. From here we can add a subview
//to th keyboard like a new button
UIButton* done = [UIButton buttonWithType:UIButtonTypeCustom];
done.frame = CGRectMake(214, 163, 106, 53);
done.titleLabel.text = @”Done”;
[done addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
[keyboard addSubview:done];
return;
}
}
}
}
Leave a comment