iphone 软键盘设置参数说明

来源:互联网 发布:js rows 编辑:程序博客网 时间:2024/05/02 15:11

当文本输入时, 文本框有几中选择用于辅助输入:

textField.clearButtonMode = UITextFieldViewModeWhileEditing;

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

 

 

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

textField.keyboardType = UIKeyboardTypeAlphabet;

  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.     UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated
  11. } UIKeyboardType;

 

键盘的呈现风格:

textField..keyboardAppearance = UIKeyboardAppearanceAlert;

  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;

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

 

键盘对输入字母自动纠正

textField.autocorrectionType = UITextAutocorrectionTypeYes;

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

 

确认键的类型

textField.returnKeyType = UIReturnKeyDone;

  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

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