UItextField彈出數字鍵盤以及隱藏鍵盤


設置UItextField的邊框

[resultTextFieldsetBorderStyle:UITextBorderStyleRoundedRect];

 

彈出數字鍵盤:

將UITextField的keyboardType設置為:

UIKeyboardTypeNumberPad

就能彈出數字鍵盤

 

鍵盤類型

typedef enum {
    UIKeyboardTypeDefault,      默認鍵盤,支持所有字符         
    UIKeyboardTypeASCIICapable, 支持ASCII的默認鍵盤
    UIKeyboardTypeNumbersAndPunctuation, 標准電話鍵盤,支持+*#字符
    UIKeyboardTypeURL,            URL鍵盤,支持.com按鈕 只支持URL字符
UIKeyboardTypeNumberPad,             數字鍵盤
UIKeyboardTypePhonePad,   電話鍵盤
    UIKeyboardTypeNamePhonePad,  電話鍵盤,也支持輸入人名
UIKeyboardTypeEmailAddress,  用於輸入電子 郵件地址的鍵盤     
UIKeyboardTypeDecimalPad,    數字鍵盤 有數字和小數點
    UIKeyboardTypeTwitter,       優化的鍵盤,方便輸入@、#字符
    UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, 
} UIKeyboardType;

 

隱藏鍵盤:

1、點擊空白處隱藏鍵盤

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

    [resultTextFieldresignFirstResponder];

    [resultTextFieldresignFirstResponder];//點擊空白處也要隱藏鍵盤

}

 

2、點擊return按鈕鍵盤消失

-(BOOL)textFieldShouldReturn:(UITextField *)textField

{

    [textField resignFirstResponder];

    returnYES;

}

 

-(void)textFieldDidEndEditing:(UITextField *)textField

{

    [textField resignFirstResponder];

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM