typedefenum{ UIKeyboardTypeDefault,// 默认键盘:支持所有字符UIKeyboardTypeASCIICapable,// 支持ASCII的默认键盘UIKeyboardTypeNumbersAndPunctuation,// 标准电话键盘,支持+*#等符号UIKeyboardTypeURL,// URL键盘,有.com按钮;只支持URL字符UIKeyboardTypeNumberPad,//数字键盘UIKeyboardTypePhonePad,// 电话键盘UIKeyboardTypeNamePhonePad,// 电话键盘,也支持输入人名字UIKeyboardTypeEmailAddress,// 用于输入电子邮件地址的键盘
} UIKeyboardType;
用法用例:
textView.keyboardtype = UIKeyboardTypeNumberPad;
typedefenum{ UIKeyboardAppearanceDefault,// 默认外观:浅灰色UIKeyboardAppearanceAlert,//深灰/石墨色
} UIKeyboardAppearance;
用法用例:
textView.keyboardAppearance=UIKeyboardAppearanceDefault;
typedefenum{ UIReturnKeyDefault,//默认:灰色按钮,标有ReturnUIReturnKeyGo,//标有Go的蓝色按钮UIReturnKeyGoogle,//标有Google的蓝色按钮,用于搜索UIReturnKeyJoin,//标有Join的蓝色按钮UIReturnKeyNext,//标有Next的蓝色按钮UIReturnKeyRoute,//标有Route的蓝色按钮UIReturnKeySearch,//标有Search的蓝色按钮UIReturnKeySend,//标有Send的蓝色按钮UIReturnKeyYahoo,//标有Yahoo!的蓝色按钮,用于搜索UIReturnKeyDone,//标有Done的蓝色按钮UIReturnKeyEmergencyCall,//紧急呼叫按钮} UIReturnKeyType;
用法用例:
textView.returnKeyType=UIReturnKeyGo;
typedefenum{ UITextAutocapitalizationTypeNone,//不自动大写UITextAutocapitalizationTypeWords,//单词首字母大写UITextAutocapitalizationTypeSentences,//句子首字母大写UITextAutocapitalizationTypeAllCharacters,//所有字母大写} UITextAutocapitalizationType;
用法用例:
textField.autocapitalizationType=UITextAutocapitalizationTypeWords;
typedefenum{ UITextAutocorrectionTypeDefault,//默认UITextAutocorrectionTypeNo,//不自动更正UITextAutocorrectionTypeYes,//自动更正} UITextAutocorrectionType;
用法用例:
textField.autocorrectionType=UITextAutocorrectionTypeYes;
textView.secureTextEntry=YES;
开启安全输入主要是用于密码或一些私人数据的输入,此时会禁用自动更正和自此缓存。
解决虚拟键盘挡住UITextField的方法:
-(BOOL)textFieldShouldReturn:(UITextField*)textField
{
NSTimeIntervalanimationDuration =0.30f;
[UIViewbeginAnimations:@"ResizeForKeyboard"context:nil];
[UIViewsetAnimationDuration:animationDuration];
CGRectrect =CGRectMake(0.0f,64,self.view.frame.size.width,self.view.frame.size.height);
self.view.frame= rect;
[UIViewcommitAnimations];
[textFieldresignFirstResponder];
returnYES;
}
- (void)textFieldDidBeginEditing:(UITextField*)textField
{
CGRectframe = textField.frame;
intoffset = frame.origin.y+32- (self.view.frame.size.height-260.0);//键盘高度216
NSTimeIntervalanimationDuration =0.30f;
[UIViewbeginAnimations:@"ResizeForKeyBoard"context:nil];
[UIViewsetAnimationDuration:animationDuration];
floatwidth =self.view.frame.size.width;
floatheight =self.view.frame.size.height;
if(offset >0)
{
CGRectrect =CGRectMake(0.0f, -offset,width,height);
self.view.frame= rect;
}
[UIViewcommitAnimations];
}
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
NSTimeIntervalanimationDuration =0.30f;
[UIViewbeginAnimations:@"ResizeForKeyboard"context:nil];
[UIViewsetAnimationDuration:animationDuration];
CGRectrect =CGRectMake(0.0f,64,self.view.frame.size.width,self.view.frame.size.height);
self.view.frame= rect;
[UIViewcommitAnimations];
[_titleTextresignFirstResponder];
[_contentTextresignFirstResponder];
}
网友评论