Custom keyboard development code for iPhone applications

Source: Internet
Author: User

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

 
 
  1. [[NSNotificationCenter defaultCenter] addObserver:self      
  2.  selector:@selector(keyboardWillShow:)         
  3.  name:UIKeyboardWillShowNotification   
  4.  object:nil]; 

Core code:

 
 
  1. -(Void) keyboardWillShow :( NSNotification *) note
  2. {
  3. UIWindow * tempWindow = [[UIApplication sharedApplication] windows] objectAtIndex: 1]; // knowledge point
  4. For (int I = 0; I <[tempWindow. subviews count]; I ++)
  5. {
  6. Keyboard = [tempWindow. subviews objectAtIndex: I];
  7. If ([[keyboard description] hasPrefix: @ "<UIKeyboard"] = YES)
  8. {
  9. [Keyboard setFrame: CGRectMake (0,460,320,345)];
  10. [Self congfigKeypad];
  11. [Keyboard addSubview: keyPadView1];
  12. }
  13. }
  14. }

For example, the configuration method can be as follows:

 
 
  1. -(Void) congfigKeypad
  2. {
  3. SearBtn * one = [[SearBtn alloc] initWithFrame: CGRectMake (81, 3, kNumPadW, kNumPadH) index: 1 ContextString: @ "1" type: kNumPadType];
  4. [One setImage: [UIImage imageNamed: @ "1.png"] forState: UIControlStateNormal];
  5. [One addTarget: self action: @ selector (buttonClickAtIndex :) forControlEvents: UIControlEventTouchUpInside];
  6. // ...... Omitted
  7. }

Add NSMutalbeString as the container of the text field string, and click the string corresponding to the append button after the button.

 
 
  1. - (void)buttonClickAtIndex:(id)sender  
  2. {  
  3.     SearBtn *btnItem = (SearBtn*)sender;  
  4.     NSString *str = btnItem->btnText;  
  5.     [s_text appendString:str];  
  6.     [sBar setText:s_text];  

Then implement a deleteChar method as the return key.

Ideas:

 
 
  1. if ([s_text length] > 0)  
  2.     {  
  3.         NSRange rang;  
  4.         rang.location = [s_text length] - 1;  
  5.         rang.length = 1;  
  6.         [s_text deleteCharactersInRange:rang];  
  7.     } 

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.