IphoneApplication CustomizationKeyboardThis is the content to be introduced in this article. I went around and read a customKeyboardSo I would like to share with you that I believe that lazy people have promoted the development of the world.IphoneWith our own software disks, we need to implement our own functions. So, as long as it is parasitic. Let's talk about the details.
Ideas:
1. Use a static method to find the UIKeyboard view in the current view (window) of the application.
2. Post your own view on the keyboard view. This is wonderful. Your own view is your own keyboard. You can play it as you like, and you can do any type of keyboard)
3. Adjust the system keyboard size as needed to meet your needs
4. Add a button to your keyboard view to implement the function.
Main Code:
Add your own class as the Observer for Keyboard Events
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(keyboardWillShow:)
- name:UIKeyboardWillShowNotification
- object:nil];
Core code:
- -(Void) keyboardWillShow :( NSNotification *) note
- {
- UIWindow * tempWindow = [[UIApplication sharedApplication] windows] objectAtIndex: 1]; // knowledge point
- For (int I = 0; I <[tempWindow. subviews count]; I ++)
- {
- Keyboard = [tempWindow. subviews objectAtIndex: I];
- If ([[keyboard description] hasPrefix: @ "<UIKeyboard"] = YES)
- {
- [Keyboard setFrame: CGRectMake (0,460,320,345)];
- [Self congfigKeypad];
- [Keyboard addSubview: keyPadView1];
- }
- }
- }
For example, the configuration method can be as follows:
- -(Void) congfigKeypad
- {
- SearBtn * one = [[SearBtn alloc] initWithFrame: CGRectMake (81, 3, kNumPadW, kNumPadH) index: 1 ContextString: @ "1" type: kNumPadType];
- [One setImage: [UIImage imageNamed: @ "1.png"] forState: UIControlStateNormal];
- [One addTarget: self action: @ selector (buttonClickAtIndex :) forControlEvents: UIControlEventTouchUpInside];
- // ...... Omitted
- }
Add NSMutalbeString as the container of the text field string, and click the string corresponding to the append button after the button.
- - (void)buttonClickAtIndex:(id)sender
- {
- SearBtn *btnItem = (SearBtn*)sender;
- NSString *str = btnItem->btnText;
- [s_text appendString:str];
- [sBar setText:s_text];
- }
Then implement a deleteChar method as the return key.
Ideas:
- if ([s_text length] > 0)
- {
- NSRange rang;
- rang.location = [s_text length] - 1;
- rang.length = 1;
- [s_text deleteCharactersInRange:rang];
- }
Now you can click a variety of text fields to create your own keyboard.
Continue Optimization
Use the textfield proxy method to control the string type, length, and response of the keyboard.
Summary:IPhoneApplication CustomizationKeyboardThe content of the development code has been introduced. I hope this article will help you!