0119——UITextField
1.默認(rèn)文本
?_loginTextField.placeholder = @"QQ號(hào)/手機(jī)";
2.設(shè)置邊框
_loginTextField.borderStyle = UITextBorderStyleRoundedRect;
?? ?typedef enum {
? ? ?UITextBorderStyleNone,?
? ? ?UITextBorderStyleLine,
? ? ?UITextBorderStyleBezel,
? ? ?UITextBorderStyleRoundedRect ?
? ?} UITextBorderStyle;
3.設(shè)置鍵盤類型
? ? _loginTextField.keyboardType = UIKeyboardTypeDefault;
?typedef enum {
? ? UIKeyboardTypeDefault, ? ? ??默認(rèn)鍵盤,支持所有字符? ? ? ? ?
? ? UIKeyboardTypeASCIICapable,??支持ASCII的默認(rèn)鍵盤
? ? UIKeyboardTypeNumbersAndPunctuation,??標(biāo)準(zhǔn)電話鍵盤,支持+*#字符
? ? UIKeyboardTypeURL,? ? ? ? ? ? URL鍵盤,支持.com按鈕?只支持URL字符
? ?UIKeyboardTypeNumberPad,? ? ? ? ? ? ??數(shù)字鍵盤
? ?UIKeyboardTypePhonePad,?? ??電話鍵盤
? ? UIKeyboardTypeNamePhonePad, ??電話鍵盤,也支持輸入人名
? ?UIKeyboardTypeEmailAddress, ??用于輸入電子?郵件地址的鍵盤? ? ?
? ?UIKeyboardTypeDecimalPad, ? ??數(shù)字鍵盤?有數(shù)字和小數(shù)點(diǎn)
? ? ? ? ? UIKeyboardTypeTwitter,? ? ? ??優(yōu)化的鍵盤,方便輸入@、#字符
? ? ? ? ? UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable,?
} UIKeyboardType;
4.更改鍵盤下方的ruturn
? ? ??_loginTextField.returnKeyType = UIReturnKeyDone;
typedef enum {
? ? ? UIReturnKeyDefault,?默認(rèn)?灰色按鈕,標(biāo)有Return
? ? ? UIReturnKeyGo,? ? ??標(biāo)有Go的藍(lán)色按鈕
? ? ? UIReturnKeyGoogle,標(biāo)有Google的藍(lán)色按鈕,用語搜索
? ? ? UIReturnKeyJoin,標(biāo)有Join的藍(lán)色按鈕
? ? ? UIReturnKeyNext,標(biāo)有Next的藍(lán)色按鈕
? ? ? UIReturnKeyRoute,標(biāo)有Route的藍(lán)色按鈕
? ? ? UIReturnKeySearch,標(biāo)有Search的藍(lán)色按鈕
? ? ? UIReturnKeySend,標(biāo)有Send的藍(lán)色按鈕
? ? ?UIReturnKeyYahoo,標(biāo)有Yahoo的藍(lán)色按鈕
? ? ?UIReturnKeyYahoo,標(biāo)有Yahoo的藍(lán)色按鈕
? ? ?UIReturnKeyEmergencyCall,?緊急呼叫按鈕
} UIReturnKeyType;
5.小叉叉
? ? ?_loginTextField.clearButtonMode?=?UITextFieldViewModeWhileEditing;
6.設(shè)置為YES時(shí)文本會(huì)自動(dòng)縮小以適應(yīng)文本窗口大小.默認(rèn)是保持原來大小,而讓長文本滾動(dòng) ?
? ? ?textFied.adjustsFontSizeToFitWidth = YES;
? ?設(shè)置自動(dòng)縮小顯示的最小字體大小
? ? ?text.minimumFontSize = 20;
7.再次編輯就清空
? ? ?text.clearsOnBeginEditing = YES;
8.UITextFieldViewMode
typedef enum {
? ? UITextFieldViewModeNever,??重不出現(xiàn)
? ? UITextFieldViewModeWhileEditing,?編輯時(shí)出現(xiàn)
? ? UITextFieldViewModeUnlessEditing,??除了編輯外都出現(xiàn)
? ? UITextFieldViewModeAlways ??一直出現(xiàn)
} UITextFieldViewMode;
9.鍵盤外觀
?textView.keyboardAppearance=UIKeyboardAppearanceDefault;
?typedef enum {
? ?UIKeyboardAppearanceDefault,?默認(rèn)外觀,淺灰色
UIKeyboardAppearanceAlert,?? ??深灰?石墨色
?} UIReturnKeyType;
10.左邊小圖,放大鏡或者解鎖圖案
UIImage * image = [UIImage imageNamed:@"search"];
? ? ??UIImageView * imageview =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
? ? ? imageview.image = image;
? ? ?_loginTextField.leftView = imageview;
? ? ?_loginTextField.leftViewMode = UITextFieldViewModeAlways;//放大鏡一直出現(xiàn)
11.return鍵隱藏鍵盤
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
? ? ?//點(diǎn)擊textField為第一響應(yīng)者,鍵盤彈出
? ? ?//取消textField第一響應(yīng)者
? ? ?[textField resignFirstResponder];
? ? ?//[textField becomeFirstResponder];
? ? ?return YES;
}
12.設(shè)置代理(狀態(tài)改變回調(diào)相應(yīng)的方法)
? ? ?_loginTextField.delegate =self;
? ??定義了一套代理用來監(jiān)聽控件的狀態(tài)變化
? ? @interface?ViewController :?UIViewController<UITextFieldDelegate>
轉(zhuǎn)載于:https://www.cnblogs.com/damonWq/p/5143296.html
與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的0119——UITextField的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iOS Xcode个人常用插件
- 下一篇: cloudera manager 及CD