一、鍵盤風格
UIKit架構支援8種風格鍵盤。
typedef enum {
UIKeyboardTypeDefault, // 預設鍵盤:支援所有字元
UIKeyboardTypeASCIICapable, // 支援ASCII的預設鍵盤
UIKeyboardTypeNumbersAndPunctuation, // 标準電話鍵盤,支援+*#等符号
UIKeyboardTypeURL, // URL鍵盤,有.com按鈕;隻支援URL字元
UIKeyboardTypeNumberPad, //數字鍵盤
UIKeyboardTypePhonePad, // 電話鍵盤
UIKeyboardTypeNamePhonePad, // 電話鍵盤,也支援輸入人名字
UIKeyboardTypeEmailAddress, // 用于輸入電子郵件位址的鍵盤
} UIKeyboardType;
用法用例:
textView.keyboardtype = UIKeyboardTypeNumberPad;
二、鍵盤外觀
UIKeyboardAppearanceDefault, // 預設外觀:淺灰色
UIKeyboardAppearanceAlert, //深灰/石墨色
} UIKeyboardAppearance;
textView.keyboardAppearance=UIKeyboardAppearanceDefault;
三、Enter鍵
UIReturnKeyDefault, //預設:灰色按鈕,标有Return
UIReturnKeyGo, //标有Go的藍色按鈕
UIReturnKeyGoogle, //标有Google的藍色按鈕,用于搜尋
UIReturnKeyJoin, //标有Join的藍色按鈕
UIReturnKeyNext, //标有Next的藍色按鈕
UIReturnKeyRoute, //标有Route的藍色按鈕
UIReturnKeySearch, //标有Search的藍色按鈕
UIReturnKeySend, //标有Send的藍色按鈕
UIReturnKeyYahoo, //标有Yahoo!的藍色按鈕,用于搜尋
UIReturnKeyDone, //标有Done的藍色按鈕
UIReturnKeyEmergencyCall, //緊急呼叫按鈕
} UIReturnKeyType;
textView.returnKeyType=UIReturnKeyGo;
四、自動大寫
UITextAutocapitalizationTypeNone, //不自動大寫
UITextAutocapitalizationTypeWords, //單詞首字母大寫
UITextAutocapitalizationTypeSentences, //句子首字母大寫
UITextAutocapitalizationTypeAllCharacters, //所有字母大寫
} UITextAutocapitalizationType;
textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
五、自動更正
UITextAutocorrectionTypeDefault,//預設
UITextAutocorrectionTypeNo,//不自動更正
UITextAutocorrectionTypeYes,//自動更正
} UITextAutocorrectionType;
textField.autocorrectionType = UITextAutocorrectionTypeYes;
六、安全文本輸入
textView.secureTextEntry=YES;
開啟安全輸入主要是用于密碼或一些私人資料的輸入,此時會禁用自動更正和自此緩存。
<a href="http://blog.csdn.net/shijiucdy/article/details/7364115">UITextField和UITextView隐藏鍵盤</a>
self._textField.returnKeyType=UIReturnKeyDone;
self._textField.delegate=self;
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
self._textView.delegate=self;
self._textView.returnKeyType=UIReturnKeyDone;
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text {
if ([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
return NO;
}

微信公衆号:
<a target="_blank" href="https://yqfile.alicdn.com/img_e00999465d1c2c1b02df587a3ec9c13d.jpg">猿人谷</a>
如果您認為閱讀這篇部落格讓您有些收獲,不妨點選一下右下角的【推薦】
如果您希望與我交流互動,歡迎關注微信公衆号
本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接配接。