1、鍵盤風格 api
UIKit框架支持8種風格鍵盤。緩存
用法用例:安全
textView.keyboardtype = UIKeyboardTypeNumberPad;app
2、鍵盤外觀框架
用法用例:spa
textView.keyboardAppearance=UIKeyboardAppearanceDefault;接口
3、回車鍵it
用法用例:io
textView.returnKeyType=UIReturnKeyGo;class
4、自動大寫
用法用例:
textField.autocapitalizationType = UITextAutocapitalizationTypeWords ;
5、自動更正
用法用例:
textField . autocorrectionType = UITextAutocorrectionTypeYes ;
6、安全文本輸入
textView.secureTextEntry=YES;
開啓安全輸入主要是用於密碼或一些私人數據的輸入,此時會禁用自動更正和自此緩存。
那麼如何設置鍵盤類型呢?
接下來,請看:
在TextviewDelegate的這個方法設置:
// return NO to disallow editing.
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
textView.keyboardtype = UIKeyboardTypeNumberPad;
//textField.returnKeyType = UIReturnKeyYahoo;//the same as search
//textField.returnKeyType = UIReturnKeyEmergencyCall; //EmergencyCall
//textField.returnKeyType = UIReturnKeyGoogle;//the same as search
textField.returnKeyType = UIReturnKeyDefault;
}
關於鍵盤的隱藏
首先在ViewController接口上添加<UITextFieldDelegate>
而後實現以下:
UITextField *text = [[UITextFieldalloc]initWithFrame:CGRectMake(100, 152, 130, 20)];
text.returnKeyType = UIReturnKeyDefault;//返回鍵類型
text.placeholder = @"請輸入姓名";
text.borderStyle = UITextBorderStyleRoundedRect;
text.keyboardAppearance = UIKeyboardTypeNamePhonePad;//鍵盤類型
text.returnKeyType = UIReturnKeyDone;
text.delegate = self;
[self.viewaddSubview:text];
實現如下方法:
-(void)viewTapped:(UITapGestureRecognizer*)tapGr{
[text resignFirstResponder];
}
-(BOOL) textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
returnYES;
}