午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    IOS UITextField 使用與方法解讀
    來源:易賢網(wǎng) 閱讀:6259 次 日期:2015-04-21 13:46:57
    溫馨提示:易賢網(wǎng)小編為您整理了“IOS UITextField 使用與方法解讀”,方便廣大網(wǎng)友查閱!

    UITextField是IOS開發(fā)中用戶交互中重要的一個控件,常被用來做賬號密碼框,輸入信息框等。

    初始化一個文字框:

    UITextField * textField = [[UITextField alloc]initWithFrame:CGRectMake(100, 30, 100, 100)];

    設(shè)置和獲取文字框文字:

    @property(nonatomic,copy) NSString *text;

    通過AttributedString創(chuàng)建和獲取文字:

    @property(nonatomic,copy) NSAttributedString *attributedText;

    設(shè)置字體顏色屬性:

    @property(nonatomic,retain) UIColor *textColor;

    設(shè)置字體屬性:

    @property(nonatomic,retain) UIFont *font;

    設(shè)置字體對齊格式:

    @property(nonatomic)NSTextAlignment textAlignment;

    設(shè)置輸入框風(fēng)格:

    @property(nonatomic) UITextBorderStyle borderStyle;

    這個風(fēng)格是一個枚舉,如下:

    typedef NS_ENUM(NSInteger, UITextBorderStyle) {

    //沒有任何邊框

    UITextBorderStyleNone,

    //線性邊框

    UITextBorderStyleLine,

    //陰影效果邊框

    UITextBorderStyleBezel,

    //原型效果邊框

    UITextBorderStyleRoundedRect

    };

    設(shè)置默認(rèn)字體屬性

    @property(nonatomic,copy) NSDictionary *defaultTextAttributes;

    這個屬性的設(shè)置會影響到全部字體的屬性。

    設(shè)置缺省時顯示的灰度字符串

    @property(nonatomic,copy) NSString *placeholder;

    通過AttributedString設(shè)置缺省字符串

    @property(nonatomic,copy) NSAttributedString *attributedPlaceholder;

    設(shè)置是否在開始編輯時清空輸入框內(nèi)容

    @property(nonatomic) BOOL clearsOnBeginEditing;

    設(shè)置字體大小是否隨寬度自適應(yīng)(默認(rèn)為NO)

    @property(nonatomic) BOOL adjustsFontSizeToFitWidth;

    設(shè)置最小字體大小

    @property(nonatomic) CGFloat minimumFontSize;

    設(shè)置背景圖片(會被拉伸)

    @property(nonatomic,retain) UIImage *background;

    設(shè)置禁用時的背景圖片

    @property(nonatomic,retain) UIImage *disabledBackground;

    是否正在編輯(只讀屬性)

    @property(nonatomic,readonly,getter=isEditing) BOOL editing;

    是否允許更改字符屬性字典

    @property(nonatomic) BOOL allowsEditingTextAttributes;

    設(shè)置屬性字典

    @property(nonatomic,copy) NSDictionary *typingAttributes;

    設(shè)置清除按鈕的顯示模式

    @property(nonatomic) UITextFieldViewMode clearButtonMode;

    這是一個枚舉,如下:

    typedef NS_ENUM(NSInteger, UITextFieldViewMode) {

    //從不顯示

    UITextFieldViewModeNever,

    //編輯的時候顯示

    UITextFieldViewModeWhileEditing,

    //非編輯的時候顯示

    UITextFieldViewModeUnlessEditing,

    //任何時候都顯示

    UITextFieldViewModeAlways

    };

    設(shè)置輸入框左邊的view

    @property(nonatomic,retain) UIView *leftView;

    設(shè)置輸入框左視圖的顯示模式

    @property(nonatomic) UITextFieldViewMode leftViewMode;

    設(shè)置輸入框右邊的view

    @property(nonatomic,retain) UIView *rightView;

    設(shè)置輸入框右視圖的顯示模式

    @property(nonatomic) UITextFieldViewMode rightViewMode;

    設(shè)置輸入框成為第一響應(yīng)時彈出的視圖和輔助視圖(類似鍵盤)

    @property (readwrite, retain) UIView *inputView;

    @property (readwrite, retain) UIView *inputAccessoryView;

    這個屬性設(shè)置是否允許再次編輯時在內(nèi)容中間插入內(nèi)容

    @property(nonatomic) BOOL clearsOnInsertion;

    注銷第一響應(yīng)(収鍵盤)

    - (BOOL)endEditing:(BOOL)force;

    UITextFieldDelegate 代理中的方法

    點擊輸入框時觸發(fā)的方法,返回YES則可以進(jìn)入編輯狀態(tài),NO則不能。

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;

    開始編輯時調(diào)用的方法

    - (void)textFieldDidBeginEditing:(UITextField *)textField;

    將要結(jié)束編輯時調(diào)用的方法,返回YES則可以結(jié)束編輯狀態(tài),NO則不能

    - (BOOL)textFieldShouldEndEditing:(UITextField *)textField;

    結(jié)束編輯調(diào)用的方法

    - (void)textFieldDidEndEditing:(UITextField *)textField;

    輸入字符時調(diào)用的方法

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;

    點擊清除按鈕時調(diào)用的函數(shù),返回YES則可以清除,點擊NO則不能清除

    - (BOOL)textFieldShouldClear:(UITextField *)textField;

    點擊return鍵觸發(fā)的函數(shù)

    - (BOOL)textFieldShouldReturn:(UITextField *)textField;

    更多信息請查看IT技術(shù)專欄

    更多信息請查看技術(shù)文章
    易賢網(wǎng)手機網(wǎng)站地址:IOS UITextField 使用與方法解讀
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2025國考·省考課程試聽報名

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報警專用圖標(biāo)