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