【iOS UIKit】UITextField(上)

一、設置邊框風格

 textF.borderStyle = UITextBorderStyleRoundedRect;

  typedef enum {

    UITextBorderStyleNone, 

    UITextBorderStyleLine,

    UITextBorderStyleBezel,

    UITextBorderStyleRoundedRect  

  } UITextBorderStyle;

二、設置背景色、背景圖、禁用時的背景圖

textF.backgroundColor = [UIColor whiteColor];

  textF.background = [UIImage imageNamed:@"dd.png"];

  textF.disabledBackground = [UIImage imageNamed:@"cc.png"];

三、輸入框中是否有個叉號,在何時顯示,用於一次性清空輸入框中的內容

textF.clearButtonMode = UITextFieldViewModeAlways;
typedef enum {
    UITextFieldViewModeNever,  重不出現
    UITextFieldViewModeWhileEditing, 編輯時出現
    UITextFieldViewModeUnlessEditing,  除了編輯外都出現
    UITextFieldViewModeAlways   一直出現
} UITextFieldViewMode;

四、是否使用暗文

textF.secureTextEntry = YES;

五、設置鍵盤的樣式

textF.keyboardType = UIKeyboardTypeNumberPad;
 
typedef enum {
    UIKeyboardTypeDefault,       //默認鍵盤,支持全部字符         
    UIKeyboardTypeASCIICapable, // 支持ASCII的默認鍵盤
    UIKeyboardTypeNumbersAndPunctuation,  //標準電話鍵盤,支持+*#字符
    UIKeyboardTypeURL,           // URL鍵盤,支持.com按鈕 只支持URL字符
    UIKeyboardTypeNumberPad,     //數字鍵盤
    UIKeyboardTypePhonePad,      //電話鍵盤
    UIKeyboardTypeNamePhonePad,   //電話鍵盤,也支持輸入人名
    UIKeyboardTypeEmailAddress,   //用於輸入電子 郵件地址的鍵盤     
    UIKeyboardTypeDecimalPad,     //數字鍵盤 有數字和小數點
    UIKeyboardTypeTwitter,        //優化的鍵盤,方便輸入@、#字符
    UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, 
} UIKeyboardType;

六、首字母是否大寫

textF.autocapitalizationType = UITextAutocapitalizationTypeNone;
 
typedef enum {
    UITextAutocapitalizationTypeNone, 不自動大寫
    UITextAutocapitalizationTypeWords,  單詞首字母大寫
    UITextAutocapitalizationTypeSentences,  句子的首字母大寫
    UITextAutocapitalizationTypeAllCharacters, 全部字母都大寫
} UITextAutocapitalizationType;

七、return鍵字樣

textF.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;

八、鍵盤外觀

textF.keyboardAppearance=UIKeyboardAppearanceDefault;
typedef enum {
UIKeyboardAppearanceDefault,   //默認外觀,淺灰色
UIKeyboardAppearanceAlert,     //深灰 石墨色
} UIReturnKeyType;

九、最右側加自定義視圖(以下)   左側相似

text.rightView=CustomView;

 textF.rightViewMode = UITextFieldViewModeAlways; 

typedef enum {

    UITextFieldViewModeNever,

    UITextFieldViewModeWhileEditing,

    UITextFieldViewModeUnlessEditing,

    UITextFieldViewModeAlways

} UITextFieldViewMode;

十、是否糾錯

textF.autocorrectionType = UITextAutocorrectionTypeNo;
 
typedef enum {
    UITextAutocorrectionTypeDefault, //默認
    UITextAutocorrectionTypeNo,   //不自動糾錯
    UITextAutocorrectionTypeYes,  //自動糾錯
} UITextAutocorrectionType;

十一、收鍵盤

[textF resignFirstResponder];
相關文章
相關標籤/搜索