UITextFiled练习
// 用户名
UITextField *userField = [[UITextField alloc] initWithFrame:CGRectMake(LOCATION_X + (CONTROL_WIDTH * 2) + 10, LOCATION_Y, CONTROL_WIDTH * 7, CONTROL_HEIGHT)];
userField.placeholder = @"请输入用户名";
/*
边框样式
typedef enum {
UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect
} UITextBorderStyle;
*/
userField.borderStyle = UITextBorderStyleBezel;
// 字体颜色
userField.textColor = [UIColor blueColor];
/*
字体对齐格式
typedef enum {
NSTextAlignmentLeft,
NSTextAlignmentCenter,
NSTextAlignmentRight,
NSTextAlignmentRight,
NSTextAlignmentCenter,
}
*/
userField.textAlignment = NSTextAlignmentLeft;
// 当编辑时文本框中的清除按钮
userField.clearButtonMode = UITextFieldViewModeWhileEditing;
userField.keyboardType = UIKeyboardTypeDefault;
userField.keyboardAppearance = UIKeyboardAppearanceDefault;
userField.returnKeyType = UIReturnKeyDone;
// 文本框中未输入文字式,Done的键为灰色,不可点状态
userField.enablesReturnKeyAutomatically = YES;
// [userField becomeFirstResponder];
// 代理方法 UITextFiledDelegate
/*
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; // return NO to disallow editing.
- (void)textFieldDidBeginEditing:(UITextField *)textField; // became first responder
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField; // return YES to allow editing to stop and to resign first responder status. NO to disallow the editing session to end
- (void)textFieldDidEndEditing:(UITextField *)textField; // may be called if forced even if shouldEndEditing returns NO (e.g. view removed from window) or endEditing:YES called
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string; // return NO to not change text
- (BOOL)textFieldShouldClear:(UITextField *)textField; // called when clear button pressed. return NO to ignore (no notifications) 清除按钮
- (BOOL)textFieldShouldReturn:(UITextField *)textField; // called when 'return' key pressed. return NO to ignore. 点击return,关闭键盘
*/
我关于UITextField常用的属性和方法就那么多,欢迎补充!!