XCODE UITextField 中的属性和用法
2015-05-28 19:26
344 查看
[b]XCODE UITextField 中的属性和用法 一些基本的用法[/b]
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
CGRect frame =CGRectMake(110, 100, 100, 30);
button.frame = frame;
button.backgroundColor = [UIColor purpleColor];
[button setTitle:@"command" forState:UIControlStateNormal];
[button setTitleColor:[UIColor yellowColor ] forState:UIControlStateNormal];
button.layer.cornerRadius = 10.0;
[button addTarget:self action:@selector(test) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview: button];
UITextField *tf = [[UITextField alloc]initWithFrame:CGRectMake(110, 150, 100, 30)];
tf.tag = 101;
tf.borderStyle =UITextBorderStyleRoundedRect ;
//UITextBorderStyleLine 输入框框边为黑色的边款,白色背景
//UITextBorderStyleBezel 输入框的边款为灰色,白色背景
//UITextBorderStyleRoundedRect 输入框为圆角,白色背景的输入框
// tf.text =@"abc" ;
tf.textColor = [UIColor purpleColor];
tf.textAlignment = NSTextAlignmentCenter;//输入的内容显示在方框的中心
//提示用户输入什么内容
tf.placeholder =@"用来提示用户";
//与密码输入时一样,输入后显现为黑色的圆点
// tf.secureTextEntry = YES;
//根据输入内容自动调节字体的大小
tf.adjustsFontSizeToFitWidth = YES;
//对用键盘输入内容进行限制和切换
//keyboardType 以下是常用的类型,其他的看单词就知道键盘的类型
//UIKeyboardTypeDecimalPad,UIKeyboardTypeNumberPad 输入框限制为输入数字,且前一个多可以输入小数点
//UIKeyboardTypeNumbersAndPunctuation 键盘为数字加标点符号
//UIKeyboardTypeDefault 为默认(常规)的键盘
tf.keyboardType = UIKeyboardTypeDefault;
//returnKeyType 键盘 显示返回(完成)时执行的操作 提示按钮 以下是常用的几种
//UIReturnKeyEmergencyCall 键盘的右下角 有一个 EmergencyCall 的(紧急呼叫)功能按钮
//UIReturnKeyGoogle 键盘的右下角 有一个 Search (功能提示按钮)
tf.returnKeyType = UIReturnKeyDefault;
//Bool, 输入时清空 输入框的内容
// tf.clearsOnBeginEditing = YES;
//clearButtonMode 输入款清除(一个叉的符号)按钮出显示的时间
// tf.clearButtonMode = UITextFieldViewModeAlways;
//设置代理
// tf.delegate = self;
//自定义设置左视图
// UIView *leftLabel = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
// leftLabel.backgroundColor = [UIColor yellowColor];
// tf.rightView = leftLabel;
// [leftLabel release];
// tf.rightViewMode = UITextFieldViewModeWhileEditing;
//自定定义键盘
// UIView *leftLabel1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
// leftLabel1.backgroundColor = [UIColor yellowColor];
// tf.inputView= leftLabel1;
// [leftLabel1 release];
//设置键盘上公用的区域
UIView *leftLabel2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 20)];
leftLabel2.backgroundColor = [UIColor yellowColor];
tf.inputAccessoryView= leftLabel2;
[leftLabel2 release];
//autocapitalizationType 设置对输入的字母大小写的设置
//UITextAutocapitalizationTypeWords 设置每个单词的首字母为大写
//UITextAutocapitalizationTypeSentences 设置一个句子中的首个单词的字母为大写
//UITextAutocapitalizationTypeAllCharacters 每个字母都大写 (7.0)以上的最后一个字母大写
//UITextAutocapitalizationTypeNone 不切换大小写
tf.autocapitalizationType = UITextAutocapitalizationTypeNone;
[self.window addSubview:tf];//2
[tf release];
[self.window makeKeyAndVisible];
return YES;
}
-(void)test
{
UITextField *tf =(UITextField *) [self.window viewWithTag:101];
//将键盘移除
[tf resignFirstResponder];
}
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
CGRect frame =CGRectMake(110, 100, 100, 30);
button.frame = frame;
button.backgroundColor = [UIColor purpleColor];
[button setTitle:@"command" forState:UIControlStateNormal];
[button setTitleColor:[UIColor yellowColor ] forState:UIControlStateNormal];
button.layer.cornerRadius = 10.0;
[button addTarget:self action:@selector(test) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview: button];
UITextField *tf = [[UITextField alloc]initWithFrame:CGRectMake(110, 150, 100, 30)];
tf.tag = 101;
tf.borderStyle =UITextBorderStyleRoundedRect ;
//UITextBorderStyleLine 输入框框边为黑色的边款,白色背景
//UITextBorderStyleBezel 输入框的边款为灰色,白色背景
//UITextBorderStyleRoundedRect 输入框为圆角,白色背景的输入框
// tf.text =@"abc" ;
tf.textColor = [UIColor purpleColor];
tf.textAlignment = NSTextAlignmentCenter;//输入的内容显示在方框的中心
//提示用户输入什么内容
tf.placeholder =@"用来提示用户";
//与密码输入时一样,输入后显现为黑色的圆点
// tf.secureTextEntry = YES;
//根据输入内容自动调节字体的大小
tf.adjustsFontSizeToFitWidth = YES;
//对用键盘输入内容进行限制和切换
//keyboardType 以下是常用的类型,其他的看单词就知道键盘的类型
//UIKeyboardTypeDecimalPad,UIKeyboardTypeNumberPad 输入框限制为输入数字,且前一个多可以输入小数点
//UIKeyboardTypeNumbersAndPunctuation 键盘为数字加标点符号
//UIKeyboardTypeDefault 为默认(常规)的键盘
tf.keyboardType = UIKeyboardTypeDefault;
//returnKeyType 键盘 显示返回(完成)时执行的操作 提示按钮 以下是常用的几种
//UIReturnKeyEmergencyCall 键盘的右下角 有一个 EmergencyCall 的(紧急呼叫)功能按钮
//UIReturnKeyGoogle 键盘的右下角 有一个 Search (功能提示按钮)
tf.returnKeyType = UIReturnKeyDefault;
//Bool, 输入时清空 输入框的内容
// tf.clearsOnBeginEditing = YES;
//clearButtonMode 输入款清除(一个叉的符号)按钮出显示的时间
// tf.clearButtonMode = UITextFieldViewModeAlways;
//设置代理
// tf.delegate = self;
//自定义设置左视图
// UIView *leftLabel = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
// leftLabel.backgroundColor = [UIColor yellowColor];
// tf.rightView = leftLabel;
// [leftLabel release];
// tf.rightViewMode = UITextFieldViewModeWhileEditing;
//自定定义键盘
// UIView *leftLabel1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
// leftLabel1.backgroundColor = [UIColor yellowColor];
// tf.inputView= leftLabel1;
// [leftLabel1 release];
//设置键盘上公用的区域
UIView *leftLabel2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 20)];
leftLabel2.backgroundColor = [UIColor yellowColor];
tf.inputAccessoryView= leftLabel2;
[leftLabel2 release];
//autocapitalizationType 设置对输入的字母大小写的设置
//UITextAutocapitalizationTypeWords 设置每个单词的首字母为大写
//UITextAutocapitalizationTypeSentences 设置一个句子中的首个单词的字母为大写
//UITextAutocapitalizationTypeAllCharacters 每个字母都大写 (7.0)以上的最后一个字母大写
//UITextAutocapitalizationTypeNone 不切换大小写
tf.autocapitalizationType = UITextAutocapitalizationTypeNone;
[self.window addSubview:tf];//2
[tf release];
[self.window makeKeyAndVisible];
return YES;
}
-(void)test
{
UITextField *tf =(UITextField *) [self.window viewWithTag:101];
//将键盘移除
[tf resignFirstResponder];
}
相关文章推荐
- pvchange命令_Linux pvchange 命令用法详解:修改物理卷属性
- HTML5标签属性及用法(一)
- scrollTop、offsetHeight和offsetTop等属性用法详解--转转转
- jquery选择器、属性设置用法经验总结
- Windows Media Player 控件属性、方法、事件的用法
- python Property属性用法
- SQLServer学习笔记<>.基础知识,一些基本命令,单表查询(null top用法,with ties附加属性,over开窗函数),排名函数
- JSP中Session用法及其属性介绍
- Android WebView属性及用法
- Android属性动画完全解析(上),初识属性动画的基本用法
- iframe标签用法详解(属性、透明、…
- 每日学习总结:CSS:Clear属性的用法、重复交易提示框、弹出提示框后页面变形、asp.net调用smtp服务发送邮件问题
- IOS控件学习:UILabel常用属性与用法
- TListView属性及用法
- css3属性中background-clip与background-origin的用法区别?
- python中string模块各属性以及函数的用法
- JSP中request属性的用法
- PHP div+css display (block none inline)属性的用法教程
- Android开发中ImageView的scaletype属性用法分析