Add or hide Keyboard bottons in iOS
In a project I’m developing, I need to hide the language button of the keyboard. To do this I thought of adding a new button with the same background color as the keyboard background color.
[doneButton setImage:[UIImage imageNamed:@"hide_language_button.png"] forState:UIControlStateHighlighted];
If you have this problem use this code to fix it.
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
…
}
-(void) keyboardDidShow:(NSNotification *)aNotification
{
[self hideLanguageButtonInKeyboard:valueTextField];
}
- (void)hideLanguageButtonInKeyboard:(UITextField *)textField
{
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(38, 173, 43, 41);
doneButton.adjustsImageWhenHighlighted = YES;
[doneButton setImage:[UIImage imageNamed:@"hide_language_button.png"] forState:UIControlStateNormal];
//[doneButton addTarget:self action:@selector(resignKeyboard) forControlEvents:UIControlEventTouchUpInside];
if ([[[UIApplication sharedApplication] windows] count] > 1) {
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
if([[keyboard description] hasPrefix:@”
{
if(textField.keyboardType == UIKeyboardTypeDefault)
[keyboard addSubview:doneButton];
}
}
}
}
Add or hide Keyboard bottons in iOS
Reviewed by Unknown
on
12:08
Rating:
No hay comentarios: