नीचे कोड numberpad iOS 8 भी पर "पूर्ण" बटन दिखाने के लिए है। मैं इस कोड को XCode-5.1.1 में आईओएस 6/7/8 डिवाइस के साथ चलाता हूं। यह पूरी तरह से काम कर रहा है।
मैं इस लिंक से प्रतिबिंब लेता हूं Can't find keyplane that supports type 4 for keyboard iPhone-Portrait-NumberPad संख्या कीबोर्ड पर जोड़ने के लिए कुछ कोड दिया गया।
@property (nonatomic, retain) UIButton *doneButton;
AddButton
- (void)addButtonToKeyboard
{
if (!self.doneButton)
{
self.doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.doneButton addTarget:self action:@selector(doneButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
}
self.doneButton.adjustsImageWhenHighlighted = NO;
[self.doneButton setTitle:@"DONE" forState:UIControlStateNormal];
[self.doneButton.titleLabel setFont:[UIFont systemFontOfSize:16.0]];
[self.doneButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self.doneButton setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
// locate keyboard view
if ([[[UIApplication sharedApplication] windows] count] <= 1) return;
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++)
{
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard found, add the button
if ([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
{
BOOL isPortrait = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation);
self.doneButton.frame = CGRectMake(((isPortrait)?0:-1),((int) (keyboard.frame.size.height*3)/4) + ((isPortrait)?0:1),(int) keyboard.frame.size.width/3-1, (isPortrait)?60:40);
[keyboard addSubview:self.doneButton];
}
//This code will work on iOS 8.0
else if([[keyboard description] hasPrefix:@"<UIInputSetContainerView"] == YES)
{
for(int i = 0 ; i < [keyboard.subviews count] ; i++)
{
UIView* hostkeyboard = [keyboard.subviews objectAtIndex:i];
if([[hostkeyboard description] hasPrefix:@"<UIInputSetHost"] == YES)
{
BOOL isPortrait = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation);
self.doneButton.frame = CGRectMake(((isPortrait) ? 0 : -1),((int) (hostkeyboard.frame.size.height*3)/4) + ((isPortrait) ? 0 : 1),(int) hostkeyboard.frame.size.width/3-1, (isPortrait) ? 60 : 40);
[hostkeyboard addSubview:self.doneButton];
}
}
}
else{}
}
}
removeButtonFromKeyboard
- (void)removeButtonFromKeyboard
{
NSArray *arTemp = [[UIApplication sharedApplication] windows];
if ([arTemp count] <= 1) return;
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++)
{
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard found, add the button
if ([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
{
for (id temp in keyboard.subviews)
{
if ([temp isKindOfClass:[UIButton class]])
{
UIButton *btnDone = (UIButton*) temp;
[btnDone removeFromSuperview];
break;
}
}
}
//This code will work on iOS 8.0
else if([[keyboard description] hasPrefix:@"<UIInputSetContainerView"] == YES)
{
for(int i = 0 ; i < [keyboard.subviews count] ; i++)
{
UIView* hostkeyboard = [keyboard.subviews objectAtIndex:i];
if([[hostkeyboard description] hasPrefix:@"<UIInputSetHost"] == YES)
{
for (id temp in hostkeyboard.subviews)
{
if ([temp isKindOfClass:[UIButton class]])
{
UIButton *btnDone = (UIButton*) temp;
[btnDone removeFromSuperview];
break;
}
}
}
}
}
else{}
}
}
मुझे किसी भी मुद्दे जानते हैं।
अद्यतन: आईओएस 7.1, वास्तविक डिवाइस पर परीक्षण - बटन तब तक नहीं जोड़ा जा रहा है जब तक कीबोर्ड शो एनीमेशन समाप्त नहीं हो जाता है। कोड नीचे दिए गए बटन को जोड़ने के लिए एक देरी कहते हैं एक बार कुंजीपटल पूरी तरह से दिखाई दे रहा है:
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
[self performSelector:@selector(addButtonToKeyboard) withObject:nil afterDelay:0.75];
}
धन्यवाद यह मेरे लिए काम करता है – poojathorat
Gr8 यह काम करता है, लेकिन जब मैं टेक्स्टफील्ड को नमपैड से सामान्य कीबोर्ड में बदलता हूं तो किया गया बटन कुंजीपटल के सामने दिखाई देता है .. मुझे क्या करना चाहिए? – iAnurag
आपको "textFieldShouldEndEditing" प्रतिनिधि विधि में removeButtonFromKeyboard को कॉल करना होगा। बस। – alishaik786