UITextField運用
1.創立方式
例:
UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, 30)];
2.常用辦法和屬性
1)邊框款式
@property(nonatomic) UITextBorderStyle borderStyle;
UITextBorderStyleNone 沒有邊框,背景默許為通明
UITextBorderStyleLine 線框,背景默許為通明
UITextBorderStyleBezel bezel 作風邊框,背景默許為通明
UITextBorderStyleRoundedRect 圓角邊框,背景默許為白色
textField.borderStyle = UITextBorderStyleBezel;
2)提示文字: placeholder
textField.placeholder = @"請輸出銀行卡密碼";
3)鍵盤類型: keyboardType
textField.keyboardType = UIKeyboardTypeNumberPad;
4)鍵盤款式: keyboardAppearance
textField.keyboardAppearance = UIKeyboardAppearanceLight;
5)密文輸出: secureTextEntry
textField.secureTextEntry = YES;
6)再次編輯能否清空: clearsOnBeginEditing
textField.clearsOnBeginEditing = YES;
7)文本橫向對齊方式: textAlignment
textField.textAlignment = NSTextAlignmentRight;
8)文本滾動: adjustsFontSizeToFitWidth
搭配 minimumFontSize一同運用
//回收鍵盤
[self.view endEditing: YES];
9)return鍵類型:returnKeyType
@property(nonatomic) UIReturnKeyType returnKeyType;
UIReturnKeyDefault,
UIReturnKeyGo,
UIReturnKeyGoogle,
UIReturnKeyJoin,
UIReturnKeyNext,
UIReturnKeyRoute,
UIReturnKeySearch,
UIReturnKeySend,
UIReturnKeyYahoo,
UIReturnKeyDone,
UIReturnKeyEmergencyCall,
10)清算按鈕形式:clearButtonMode
@property(nonatomic) UITextFieldViewMode clearButtonMode;
UITextFieldViewModeNever,
UITextFieldViewModeWhileEditing,
UITextFieldViewModeUnlessEditing,
UITextFieldViewModeAlways
3.UITextFieldDelegate 協議
1)能否可以進入編輯形式
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;
//前往NO,無法進入編輯形態
return YES;
2)文本框曾經進入編輯形式
-(void)textFieldDidBeginEditing:(UITextField *)textField;
3)文本框能否可以完畢編輯形式
-(BOOL)textFieldShowEndEditing:(UITextField *)textField;
//前往NO,無法完畢編輯形態
return YES;
4)文本框已完畢編輯形式
-(void)textFieldDidEndEditing:(UITextField *)textField;
5)能否可以點擊clear按鈕
-(BOOL)textFieldShouldClear:(UITextField *)textField;
//前往NO,點擊clear按鈕無呼應
return YES;
6)能否可以點擊return按鈕
-(BOOL)textFieldShouldReturn:(UITextField *)textField;
//移除第一呼應者
[textField resignFirstResponder];
return YES;
7)允許修正內容
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string; 例如: if (textField.text.length >= 6) { if ([string isEqualToString:@""]) { return YES; } return NO; } return YES; }
【iOS開發-UI (五)UITextField】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!