UITextFeild的基本属性
textField 基本屬性
?_textField.frame?=?CGRectMake(0,?0,?200,?50);??
????_textField.delegate?=?self;??
????_textField.text?=?str;??
????[_textField?becomeFirstResponder];??
/*?
?????設置背景色、背景圖片。設置了背景圖片后,背景色設置無效?
?????如果background為nil,disabledBackground無效?
?????*/??
????_textField.background?=?[UIImage?imageNamed:@"返回-按下"];??
????_textField.disabledBackground?=?[UIImage?imageNamed:@"返回-未激活"];??
//????_textField.enabled?=?NO;??
????_textField.backgroundColor?=?[UIColor?blueColor];??
????_textField.placeholder?=?@"輸入文本…";??
/*?
?????設置為YES時文本會自動縮小以適應文本窗口大小.默認是保持原來大小,而讓長文本滾動?
?????*/??
????_textField.adjustsFontSizeToFitWidth?=?YES;??
//設置自動縮小顯示的最小字體大小,adjustsFontSizeToFitWidth為YES才會起作用??
????_textField.minimumFontSize?=?20;??
????_textField.font?=?[UIFont?systemFontOfSize:30.0f];??
/*?
?????內容對齊方式?
?????內容的垂直對齊方式??UITextField繼承自UIControl,此類中有一個屬性contentVerticalAlignment?
?????*/??
????_textField.textAlignment?=?UITextAlignmentLeft;??
????_textField.contentVerticalAlignment?=?UIControlContentVerticalAlignmentCenter;??
/*?
?????typedef?enum?{?
?????UITextBorderStyleNone,?
?????UITextBorderStyleLine,?
?????UITextBorderStyleBezel,?
?????UITextBorderStyleRoundedRect?
?????}?UITextBorderStyle;?
?????*/??
????_textField.borderStyle?=?UITextBorderStyleBezel;??
/*?
?????每輸入一個字符就變成點?用語密碼輸入?
?????*/??
????_textField.secureTextEntry?=?NO;??
/*?
?????//輸入框中是否有個叉號,在什么時候顯示,用于一次性刪除輸入框中的內容?
?????typedef?enum?{?
?????UITextFieldViewModeNever, 重不出現?
?????UITextFieldViewModeWhileEditing,?編輯時出現?
?????UITextFieldViewModeUnlessEditing, 除了編輯外都出現?
?????UITextFieldViewModeAlways? 一直出現?
?????}?UITextFieldViewMode;?
?????*/??
????_textField.clearButtonMode?=?UITextFieldViewModeWhileEditing;??
/*?
?????開始編輯,清空數據?
?????*/??
????_textField.clearsOnBeginEditing?=?NO;??
/*?
?????//是否糾錯?
?????typedef?enum?{?
?????UITextAutocorrectionTypeDefault,?默認?
?????UITextAutocorrectionTypeNo,? 不自動糾錯?
?????UITextAutocorrectionTypeYes, 自動糾錯?
?????}?UITextAutocorrectionType;?
?????*/??
????_textField.autocorrectionType?=?UITextAutocorrectionTypeYes;??
/*?
?????//首字母是否大寫?
?????typedef?enum?{?
?????UITextAutocapitalizationTypeNone,?不自動大寫?
?????UITextAutocapitalizationTypeWords, 單詞首字母大寫?
?????UITextAutocapitalizationTypeSentences, 句子的首字母大寫?
?????UITextAutocapitalizationTypeAllCharacters,?所有字母都大寫?
?????}?UITextAutocapitalizationType;?
?????*/??
????_textField.autocapitalizationType?=?UITextAutocapitalizationTypeWords;??
/*?
?????鍵盤?
?????typedef?enum?{?
?????UIKeyboardTypeDefault,????? 默認鍵盤,支持所有字符?
?????UIKeyboardTypeASCIICapable, 支持ASCII的默認鍵盤?
?????UIKeyboardTypeNumbersAndPunctuation, 標準電話鍵盤,支持+*#字符?
?????UIKeyboardTypeURL,????????????URL鍵盤,支持.com按鈕?只支持URL字符?
?????UIKeyboardTypeNumberPad,???????????? 數字鍵盤?
?????UIKeyboardTypePhonePad, ? 電話鍵盤?
?????UIKeyboardTypeNamePhonePad,? 電話鍵盤,也支持輸入人名?
?????UIKeyboardTypeEmailAddress,? 用于輸入電子?郵件地址的鍵盤?
?????UIKeyboardTypeDecimalPad,??? 數字鍵盤?有數字和小數點?
?????UIKeyboardTypeTwitter,?????? 優化的鍵盤,方便輸入@、#字符?
?????UIKeyboardTypeAlphabet?=?UIKeyboardTypeASCIICapable,?
?????}?UIKeyboardType;?
?????*/??
????_textField.keyboardType?=?UIKeyboardTypeDefault;??
/*?
?????//return鍵變成什么鍵?
?????typedef?enum?{?
?????UIReturnKeyDefault,?默認?灰色按鈕,標有Return?
?????UIReturnKeyGo,???? 標有Go的藍色按鈕?
?????UIReturnKeyGoogle,標有Google的藍色按鈕,用語搜索?
?????UIReturnKeyJoin,標有Join的藍色按鈕?
?????UIReturnKeyNext,標有Next的藍色按鈕?
?????UIReturnKeyRoute,標有Route的藍色按鈕?
?????UIReturnKeySearch,標有Search的藍色按鈕?
?????UIReturnKeySend,標有Send的藍色按鈕?
?????UIReturnKeyYahoo,標有Yahoo的藍色按鈕?
?????UIReturnKeyYahoo,標有Yahoo的藍色按鈕?
?????UIReturnKeyEmergencyCall,?緊急呼叫按鈕?
?????}?UIReturnKeyType;?
?????*/??
????_textField.returnKeyType?=?UIReturnKeyDone;??
/*?
?????//鍵盤外觀?
?????typedef?enum?{?
?????UIKeyboardAppearanceDefault,?默認外觀,淺灰色?
?????UIKeyboardAppearanceDark, ? 深灰?石墨色?
?????UIKeyboardAppearanceLight?淺灰色?
?????}?UIReturnKeyType;?
?????*/??
????_textField.keyboardAppearance=UIKeyboardAppearanceDefault;??
/*?
?????設置左右的兩個view?
?????*/??
//????UIImageView?*imgView?=?[[UIImageView?alloc]?initWithImage:[UIImage?imageNamed:@"image_right"]];??
//????imgView.frame?=?CGRectMake(0,?0,?20,?20);??
//????_textField.rightView?=?imgView;??
//????_textField.rightViewMode?=?UITextFieldViewModeAlways;???//?同上??
????UIImageView?*imgView?=?[[UIImageView?alloc]?initWithImage:[UIImage?imageNamed:@"image_left"]];??
????imgView.frame?=?CGRectMake(0,?0,?20,?20);??
????_textField.leftView?=?imgView;??
????_textField.leftViewMode?=?UITextFieldViewModeAlways;???//?同上??
/*?
?????重寫繪制行為?
?????除了UITextField對象的風格選項,你還可以定制化UITextField對象,為他添加許多不同的重寫方法,來改變文本字段的顯示行為。這些方法都會返回一個CGRect結構,制定了文本字段每個部件的邊界范圍。以下方法都可以重寫。?
??????
?????–?textRectForBounds: ?? //重寫來重置文字區域?
?????–?drawTextInRect: ?????? //改變繪文字屬性.重寫時調用super可以按默認圖形屬性繪制,若自己完全重寫繪制函數,就不用調用super了.?
?????–?placeholderRectForBounds: //重寫來重置占位符區域?
?????–?drawPlaceholderInRect: //重寫改變繪制占位符屬性.重寫時調用super可以按默認圖形屬性繪制,若自己完全重寫繪制函數,就不用調用super了.?
?????–?borderRectForBounds: //重寫來重置邊緣區域?
?????–?editingRectForBounds: //重寫來重置編輯區域?
?????–?clearButtonRectForBounds: //重寫來重置clearButton位置,改變size可能導致button的圖片失真?
?????–?leftViewRectForBounds:?
?????–?rightViewRectForBounds:?
?????*/
轉載于:https://www.cnblogs.com/sundaysme/p/10330716.html
總結
以上是生活随笔為你收集整理的UITextFeild的基本属性的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IP地址、子网掩码、网关、路由器等知识积
- 下一篇: H5与企业微信jssdk集成