UITextField学习技巧
2015-10-26 12:15
387 查看
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常用的属性和方法就那么多,欢迎补充!!
// 用户名
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常用的属性和方法就那么多,欢迎补充!!
相关文章推荐
- codeforces 591 D. Chip 'n Dale Rescue Rangers
- UIAlertController
- UIBlurEffect系统自带毛玻璃效果
- 原生的强大DOM选择器querySelector
- SqlCommandBuilder如何实现批量更新
- HDOJ 题目4000 Fruit Ninja(树状数组)
- Virtualbox WDDM之DxgkDdiQueryChildStatus
- json_value.asm: No such file or directory
- ClientDataSet + DataSetProvider + FDQuery 的bug
- Virtualbox WDDM之DxgkDdiQueryChildRelations
- UITabBarController的简单使用
- 错误The request sent by the client was syntactically incorrect的解决
- iOS UIPopoverController的使用
- Druid——阿里巴巴的开源项目(关于数据库连接、监控)
- enqueue waits
- StringBuilder清空方式
- 如何在quicksettings中增加一个新的buttons
- [翻译 by Zephyr] README In Spark Building
- iOS-UIKit( UILabel.h - -解读)
- Unique Binary Search Trees