設置邊框樣式,只有設置了才會顯示邊框樣式
text.borderStyle = UITextBorderStyleRoundedRect;
typedef enum {
UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect
} UITextBorderStyle;
輸入框中是否有個叉號,在什么時候顯示,用于一次性刪除輸入框中的內容
text.clearButtonMode = UITextFieldViewModeAlways;
```
>typedef enum {
UITextFieldViewModeNever, 重不出現
UITextFieldViewModeWhileEditing, 編輯時出現
UITextFieldViewModeUnlessEditing, 除了編輯外都出現
UITextFieldViewModeAlways 一直出現
} UITextFieldViewMode;
每輸入一個字符就變成點 用語密碼輸入
text.secureTextEntry = YES;
是否糾錯
text.autocorrectionType = UITextAutocorrectionTypeNo;
>typedef enum {
UITextAutocorrectionTypeDefault, 默認
UITextAutocorrectionTypeNo, 不自動糾錯
UITextAutocorrectionTypeYes, 自動糾錯
} UITextAutocorrectionType;
再次編輯就清空
text.clearsOnBeginEditing = YES;
設置為YES時文本會自動縮小以適應文本窗口大小.默認是保持原來大小,而讓長文本滾動
textFied.adjustsFontSizeToFitWidth = YES;
設置鍵盤的樣式
text.keyboardType = UIKeyboardTypeNumberPad;
>typedef enum {
UIKeyboardTypeDefault, 默認鍵盤,支持所有字符
UIKeyboardTypeASCIICapable, 支持ASCII的默認鍵盤
UIKeyboardTypeNumbersAndPunctuation, 標準電話鍵盤,支持+*#字符
UIKeyboardTypeURL, URL鍵盤,支持.com按鈕 只支持URL字符
UIKeyboardTypeNumberPad, 數字鍵盤
UIKeyboardTypePhonePad, 電話鍵盤
UIKeyboardTypeNamePhonePad, 電話鍵盤,也支持輸入人名
UIKeyboardTypeEmailAddress, 用于輸入電子 郵件地址的鍵盤
UIKeyboardTypeDecimalPad, 數字鍵盤 有數字和小數點
UIKeyboardTypeTwitter, 優化的鍵盤,方便輸入@、#字符
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable,
} UIKeyboardType;
首字母是否大寫
text.autocapitalizationType = UITextAutocapitalizationTypeNone;
>typedef enum {
UITextAutocapitalizationTypeNone, 不自動大寫
UITextAutocapitalizationTypeWords, 單詞首字母大寫
UITextAutocapitalizationTypeSentences, 句子的首字母大寫
UITextAutocapitalizationTypeAllCharacters, 所有字母都大寫
} UITextAutocapitalizationType;
return鍵變成什么鍵
text.returnKeyType =UIReturnKeyDone;
>typedef enum {
UIReturnKeyDefault, 默認 灰色按鈕,標有Return
UIReturnKeyGo, 標有Go的按鈕
UIReturnKeyGoogle,標有Google的按鈕
UIReturnKeyJoin,標有Join的按鈕
UIReturnKeyNext,標有Next的按鈕
UIReturnKeyRoute,標有Route的按鈕
UIReturnKeySearch,標有Search的按鈕
UIReturnKeySend,標有Send的按鈕
UIReturnKeyYahoo,標有Yahoo的按鈕
UIReturnKeyYahoo,標有Yahoo的按鈕
UIReturnKeyEmergencyCall, 緊急呼叫按鈕
} UIReturnKeyType;
鍵盤外觀
textView.keyboardAppearance=UIKeyboardAppearanceDefault;
>typedef enum {
UIKeyboardAppearanceDefault, 默認外觀,淺灰色
UIKeyboardAppearanceAlert, 深灰 石墨色
} UIReturnKeyType;
***
###限制只能輸入一定長度的字符
使用UITextFieldDelegate的方法實現
-(BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
{
//string指此時輸入的那個字符 textField指此時正在輸入的那個輸入框 返回YES就是可以改變輸入框的值
NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string]; //得到輸入框的內容
if (self.myTextField == textField) //判斷是否是我們想要限定的那個輸入框
{
if ([toBeString length] > 20) { //如果輸入框內容大于20則彈出警告
UIAlertView *alert =[ [UIAlertView alloc] initWithTitle:@"警告" message:@"超過輸入最大長度" delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil];
[alert show];
return NO;
}
}
return YES;
}