The idea is parasitic...
I believe that lazy people have promoted the development of the world. Since the iphone has its own software disk, what should we do to implement its own functions.
So, as long as it is parasitic.
Thank you for the inspiration from alan's reprinted article.
Http://www.cocoachina.com/bbs/read.php? Tid-3999.html
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. (wonderful. This view is your own keyboard. whatever type of keyboard you can use, you can do it)
3. Adjust the system keyboard size as needed to meet your needs
4. Add a method to the button on the view of your keyboard to implement the function.
Main Code:
Add your own class as the Observer for Keyboard Events
Copy code
- [[Nsicationcenter center defacenter center] addObserver: self
- Selector: @ selector (keyboardWillShow :)
- Name: UIKeyboardWillShowNotification
- Object: nil];
|
Core code:
Copy 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:
Copy code
- -(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.
Copy code
- -(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:
Copy code
- If ([s_text length]> 0)
- {
- Nsange 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. [This post was edited by evangel at, September 17,.]
Image: Image 1.png
Image: Image 2.png
Http://www.cocoachina.com/bbs/read.php? Tid-12429.html