zoukankan      html  css  js  c++  java
  • iPhone 和输入,键盘相关的属性

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

     

    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. }  

    id 博主 = [[KILONET.CNBLOGS.COM alloc] initWithValue:@"天堂向右,我依然向左"

                  网名:@"老舟"

                  兴趣:@"影音,阅读"

                  动态:@"系统架构设计,Android通信模块开发"

                  网址:@"http://kilonet.cnblogs.com"
                  签名:@"--------------------------------------------------

                                  Stay Hungry , Stay Foolish

                                  求  知  若  渴,处  事  若  愚

                              --------------------------------------------------"

                  ];         // Never Release

  • 相关阅读:
    【POJ 1958】 Strange Towers of Hanoi
    【HNOI 2003】 激光炸弹
    【POJ 3263】 Tallest Cow
    【POJ 2689】 Prime Distance
    【POJ 2777】 Count Color
    【POJ 1995】 Raising Modulo Numbers
    【POJ 1845】 Sumdiv
    6月16日省中集训题解
    【TJOI 2018】数学计算
    【POJ 1275】 Cashier Employment
  • 原文地址:https://www.cnblogs.com/KiloNet/p/1807323.html
Copyright © 2011-2022 走看看