1.樣式風(fēng)格
UITextBorderStyleNone //沒有邊框,默認(rèn)風(fēng)格
UITextBorderStyleLine //線框,默認(rèn)背景透明
UITextBorderStyleBezel //bezel風(fēng)格邊框
UITextBorderStyleRoundedRect //圓角邊框,背景
2.常用屬性
text //設(shè)置和獲取文本內(nèi)容
textColor //設(shè)置文本顏色
font //設(shè)置文本字體
textAlignment //設(shè)置對(duì)齊方式
placeholder //設(shè)置提示文本
adjustsFontSizeToFitWidth //自適應(yīng)調(diào)整字體大小 默認(rèn)為NO
background "UIImage" //設(shè)置背景,需要將風(fēng)格設(shè)為UITextBorderStyleNone
disabledBackground //設(shè)置不可用時(shí)的背景圖片
clearsOnBeginEditing //編輯是是否可以刪除內(nèi)容 默認(rèn)為NO
clearButtonMode // 清楚按鈕的模式,默認(rèn)不出現(xiàn)
autocapitalizationType
//UITextAutocapitalizationTypeNone 設(shè)置首字母為小寫
//UITextAutocapitalizationTypeSentences 設(shè)置首字母為大寫
keyboardType // 修改鍵盤類型
UIKeyboardTypeDefault //默認(rèn)鍵盤樣式
UIKeyboardTypeNumberPad //純數(shù)字鍵盤樣式
UIKeyboardTypePhonePad //電話號(hào)碼鍵盤樣式
UIKeyboardTypeEmailAddress //郵箱地址樣式
secureTextEntry "BOOL" 設(shè)置密文文本,一般在用戶輸入密碼時(shí)
3.UITextField代理方法
//是否允許編輯
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{}
//已經(jīng)開始編輯
- (void)textFieldDidBeginEditing:(UITextField *)textField{}
//是否允許結(jié)束編輯
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{}
//已經(jīng)結(jié)束編輯
- (void)textFieldDidEndEditing:(UITextField *)textField{}
//是否允許清除
- (BOOL)textFieldShouldClear:(UITextField *)textField{}
//是否允許return
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
//取消第一響應(yīng)(鍵盤消失)
[textField resignFirstResponder] ;
//讓下一個(gè)textField成為響應(yīng)者
// if (textField != self.fd2) {
// [self.fd2 becomeFirstResponder];
// }
return YES;
}
//改變textField的文本內(nèi)容時(shí)調(diào)用
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
return YES;
}
4.鍵盤的通知
UIKeyboardWillChangeFrameNotification //鍵盤frame改變
UIKeyboardWillShowNotification //鍵盤即將出現(xiàn)
UIKeyboardDidShowNotification //鍵盤已經(jīng)出現(xiàn)
UIKeyboardWillHideNotification //鍵盤即將消失
UIKeyboardDidHideNotification //鍵盤已經(jīng)消失