iOS控件之UITextField
2016-06-01 12:43
483 查看
文本输入控件UITextField
一,作用:用户输入文字
二,常用属性
// 设置和获取文本内容,默认nil
@property(nonatomic,copy) NSString *text;
// 设置文本内容颜色
@property(nonatomic,retain) UIColor *textColor;
// 设置字体
@property(nonatomic,retain) UIFont *font
// 对齐样式
@property(nonatomic) NSTextAlignment textAlignment;
// 设置风格,默认没有风格,需要设置
@property(nonatomic) UITextBorderStyle borderStyle;
// 提示用户输入内容文本
@property(nonatomic,copy) NSString *placeholder;
// 用户编辑时是否clear内容,默认为NO
@property(nonatomic) BOOL clearsOnBeginEditing;
// 自适应调整字体大小,默认为NO
@property(nonatomic) BOOL adjustsFontSizeToFitWidth;
三,常用属性
// 设置代理
@property(nonatomic,assign) id<UITextFieldDelegate> delegate;
// 设置背景,需要将textField实例的风格设置为None
@property(nonatomic,retain) UIImage *background;
// 设置textField不可用时的背景图片
@property(nonatomic,retain) UIImage *disabledBackground;
// 设置是否可编辑
@property(nonatomic,readonly,getter=isEditing) BOOL editing;
// 清除按钮的模式,默认不出现
@property(nonatomic) UITextFieldViewMode clearButtonMode;
// 自定义左视图
@property(nonatomic,retain) UIView *leftView;
// 自定义左视图出现的模式
@property(nonatomic) UITextFieldViewMode leftViewMode;
// 不用系统键盘,自定义键盘
@property (readwrite, retain) UIView *inputView;
// 系统键盘和自定义键盘共存
@property (readwrite, retain) UIView *inputAccessoryView;
// 自动大写类型
@property(nonatomic) UITextAutocapitalizationType autocapitalizationType;
// 检查拼写是否正确
@property(nonatomic) UITextAutocorrectionType autocorrectionType;
// 修改键盘类型
@property(nonatomic) UIKeyboardType keyboardType;
// 修改返回类型
@property(nonatomic) UIReturnKeyType returnKeyType;
// 是否安全输入,比如用户输入密码
@property(nonatomic,getter=isSecureTextEntry) BOOL secureTextEntry;
四,UITextFieldDemo
一,作用:用户输入文字
二,常用属性
// 设置和获取文本内容,默认nil
@property(nonatomic,copy) NSString *text;
// 设置文本内容颜色
@property(nonatomic,retain) UIColor *textColor;
// 设置字体
@property(nonatomic,retain) UIFont *font
// 对齐样式
@property(nonatomic) NSTextAlignment textAlignment;
// 设置风格,默认没有风格,需要设置
@property(nonatomic) UITextBorderStyle borderStyle;
// 提示用户输入内容文本
@property(nonatomic,copy) NSString *placeholder;
// 用户编辑时是否clear内容,默认为NO
@property(nonatomic) BOOL clearsOnBeginEditing;
// 自适应调整字体大小,默认为NO
@property(nonatomic) BOOL adjustsFontSizeToFitWidth;
三,常用属性
// 设置代理
@property(nonatomic,assign) id<UITextFieldDelegate> delegate;
// 设置背景,需要将textField实例的风格设置为None
@property(nonatomic,retain) UIImage *background;
// 设置textField不可用时的背景图片
@property(nonatomic,retain) UIImage *disabledBackground;
// 设置是否可编辑
@property(nonatomic,readonly,getter=isEditing) BOOL editing;
// 清除按钮的模式,默认不出现
@property(nonatomic) UITextFieldViewMode clearButtonMode;
// 自定义左视图
@property(nonatomic,retain) UIView *leftView;
// 自定义左视图出现的模式
@property(nonatomic) UITextFieldViewMode leftViewMode;
// 不用系统键盘,自定义键盘
@property (readwrite, retain) UIView *inputView;
// 系统键盘和自定义键盘共存
@property (readwrite, retain) UIView *inputAccessoryView;
// 自动大写类型
@property(nonatomic) UITextAutocapitalizationType autocapitalizationType;
// 检查拼写是否正确
@property(nonatomic) UITextAutocorrectionType autocorrectionType;
// 修改键盘类型
@property(nonatomic) UIKeyboardType keyboardType;
// 修改返回类型
@property(nonatomic) UIReturnKeyType returnKeyType;
// 是否安全输入,比如用户输入密码
@property(nonatomic,getter=isSecureTextEntry) BOOL secureTextEntry;
四,UITextFieldDemo
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; self.window.backgroundColor = [UIColor purpleColor]; UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(90, 80, 140, 35); [button addTarget:self action:@selector(test) forControlEvents:UIControlEventTouchUpInside]; [self.window addSubview:button]; UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(60, 180, 200, 35)]; tf.tag = 101; tf.delegate = self; // 设置代理 tf.textColor = [UIColor redColor]; tf.placeholder = @"用来提示用户"; tf.adjustsFontSizeToFitWidth = YES; tf.clearsOnBeginEditing = YES; tf.clearButtonMode = UITextFieldViewModeWhileEditing; // tf.background = [UIImage imageNamed:@"navigation"]; tf.borderStyle = UITextBorderStyleRoundedRect; [self.window addSubview:tf]; [tf release]; // 成为第一响应者 // [tf becomeFirstResponder]; // 自定义clear按钮 // UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)]; // view.backgroundColor = [UIColor yellowColor]; // tf.rightView = view; // [view release]; // tf.rightViewMode = UITextFieldViewModeUnlessEditing; // 自定义系统键盘 // UIView *csView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)]; // csView.backgroundColor = [UIColor yellowColor]; // tf.inputView = csView; // [csView release]; // 共用 // UIView *csView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; // csView.backgroundColor = [UIColor yellowColor]; // tf.inputAccessoryView = csView; // [csView release]; // tf.secureTextEntry = YES;//设置密码 // tf.keyboardType = UIKeyboardTypeNumberPad; // tf.returnKeyType = UIReturnKeyDone; tf.autocapitalizationType = UITextAutocapitalizationTypeNone; [self.window makeKeyAndVisible]; return YES; } - (void)test { UITextField *tf = (UITextField *)[self.window viewWithTag:101]; // 将键盘移除 [tf resignFirstResponder]; }
相关文章推荐
- UI适配攻略!安卓&苹果碎片化
- iOS控件之UIButton
- 五分钟搞懂Android的消息机制(Handle,Looper,MessageQueue)
- iOS控件之UILabel
- LeetCode:Increasing Triplet Subsequence
- 1099. Build A Binary Search Tree (30)
- UIRL编码
- 【kaldi】Kaldi tutorial翻译之Prerequisites(前提条件)-kaldi学习前必备梳理
- java.lang.IllegalArgumentException: No converter found for return value of type: class
- SystemUI浅析
- Light oj-1100 - Again Array Queries,又是这个题,上次那个题用的线段树,这题差点就陷坑里了,简单的抽屉原理加暴力就可以了,真是坑~~
- Android 子线程更新UI:handle和runOnUiThread()
- pch文件导入uikit报错 could not build module 'uikit'
- 【iOS开发-91】GCD的同步异步串行并行、NSOperation和NSOperationQueue一级用dispatch_once实现单例(转载)
- Codeforces 645E Intellectual Inquiry (贪心+DP)
- Tair-淘宝自主开发的一个分布式key/value存储系统
- j2ee四大作用域pagecontext,request,session,ServletContext(转)
- 三维箭头quiver3的用法
- UEFI BIOS模式下Windows系统启动过程以及引导文件修复方法
- Android标题透明沉浸式UI