软键盘的属性设置

textField.clearButtonMode = UITextFieldViewModeWhileEditing;

Java代码 
  1. typedef enum {  
  2.     UITextFieldViewModeNever, //clear button 永远不出现  
  3.     UITextFieldViewModeWhileEditing, //编辑的时候出现  
  4.     UITextFieldViewModeUnlessEditing, //未编辑的时候出现  
  5.     UITextFieldViewModeAlways //永远都出现  
  6. } UITextFieldViewMode;  

 

 

弹出的键盘类型也可以辅助快速输入:

textField.keyboardType = UIKeyboardTypeAlphabet;

Java代码 
  1. typedef enum {  
  2.     UIKeyboardTypeDefault,                // Default type for the current input method.  
  3.     UIKeyboardTypeASCIICapable,           // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active  
  4.     UIKeyboardTypeNumbersAndPunctuation,  // Numbers and assorted punctuation.  
  5.     UIKeyboardTypeURL,                    // A type optimized for URL entry (shows . / .com prominently).  
  6.     UIKeyboardTypeNumberPad,              // A number pad (0-9). Suitable for PIN entry.  
  7.     UIKeyboardTypePhonePad,               // A phone pad (1-9, *, 0, #, with letters under the numbers).  
  8.     UIKeyboardTypeNamePhonePad,           // A type optimized for entering a person's name or phone number.  
  9.     UIKeyboardTypeEmailAddress,           // A type optimized for multiple email address entry (shows space @ . prominently).  
  10.   
  11.     UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated  
  12.   
  13. } UIKeyboardType;  

 

键盘的呈现风格:

textField..keyboardAppearance = UIKeyboardAppearanceAlert;

Java代码 
  1. typedef enum {  
  2.     UIKeyboardAppearanceDefault,          // Default apperance for the current input method.  
  3.     UIKeyboardAppearanceAlert,            // Appearance suitable for use in "alert" scenarios.  
  4. } UIKeyboardAppearance;  

 

键盘对输入字母的控制:

 

textField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;

 

Java代码 
  1. typedef enum {  
  2.     UITextAutocapitalizationTypeNone, //什么也不做  
  3.     UITextAutocapitalizationTypeWords, //单词首字母大写  
  4.     UITextAutocapitalizationTypeSentences, //句子首字母大些  
  5.     UITextAutocapitalizationTypeAllCharacters, //所有字母大些  
  6. } UITextAutocapitalizationType;  

 

键盘对输入字母自动纠正

textField.autocorrectionType = UITextAutocorrectionTypeYes;

Java代码 
  1. typedef enum {  
  2.     UITextAutocorrectionTypeDefault,  
  3.     UITextAutocorrectionTypeNo,  
  4.     UITextAutocorrectionTypeYes,  
  5. } UITextAutocorrectionType;  

 

 

确认键的类型

textField.returnKeyType = UIReturnKeyDone;

 

Java代码 
  1. typedef enum {  
  2.     UIReturnKeyDefault,  
  3.     UIReturnKeyGo,  
  4.     UIReturnKeyGoogle,  
  5.     UIReturnKeyJoin,  
  6.     UIReturnKeyNext,  
  7.     UIReturnKeyRoute,  
  8.     UIReturnKeySearch,  
  9.     UIReturnKeySend,  
  10.     UIReturnKeyYahoo,  
  11.     UIReturnKeyDone,  
  12.     UIReturnKeyEmergencyCall,  
  13. } UIReturnKeyType;  

 

 

最后一个技巧,也是网上收集,键盘透明以及增加一个按键的应用:

 [[NSNotificationCenter defaultCenter] addObserver:self

Java代码 
  1.                                              selector:@selector(keyboardWillShow:)   
  2.                                                  name:UIKeyboardWillShowNotification   
  3.                                                object:nil];  
  4.   
  5.   
  6.   
  7. --------------------  
  8. - (void)keyboardWillShow:(NSNotification *)note {    
  9.     // create custom button  
  10.     UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];  
  11.     doneButton.frame = CGRectMake(016310653);  
  12.     doneButton.adjustsImageWhenHighlighted = NO;  
  13.     [doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];  
  14.     [doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];  
  15.     [doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];  
  16.   
  17.     // locate keyboard view  
  18.     UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];  
  19.     UIView* keyboard;  
  20.     for(int i=0; i<[tempWindow.subviews count]; i++) {  
  21.         keyboard = [tempWindow.subviews objectAtIndex:i];  
  22.         // keyboard view found; add the custom button to it  
  23.         if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)  
  24.             [keyboard addSubview:doneButton];  
  25.     }  
  26. }  

猜你喜欢

转载自zani.iteye.com/blog/1609772