UITextField 基本属性使用
//设置文本框 透明度
tf.alpha = ;
//设置文本颜色
tf.textColor = [UIColor orangeColor];
//设置文本文字 格式
tf.font = [UIFont systemFontOfSize:];
/*设置文本对齐方式
NSTextAlignmentLeft 左
NSTextAlignmentRight 右
NSTextAlignmentCenter 中
*/
tf.textAlignment = NSTextAlignmentCenter;
/* 设置文本框 边框格式
UITextBorderStyleNone 默认无 UITextBorderStyleLine 线边框 UITextBorderStyleBezel 阴影效果边框 UITextBorderStyleRoundedRect 圆边效果
*/
tf.borderStyle = UITextBorderStyleBezel;
//文本框 格式化文字输入
NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
[dic setObject:[UIColor redColor] forKey:NSForegroundColorAttributeName]; NSAttributedString * attr = [[NSAttributedString alloc]initWithString:@"cccccccc" attributes:dic];
// tf.attributedText = attr;
//defaultTextAttributes 设置文本框的 默认字体属性
//输入的字成为 点用于密码框
tf.secureTextEntry = NO; //首字母是否大写
/*
UITextAutocapitalizationTypeNone, 不自动大写 UITextAutocapitalizationTypeWords, 单词首字母大写 UITextAutocapitalizationTypeSentences, 句子的首字母大写 UITextAutocapitalizationTypeAllCharacters, 所有字母都大写
*/
tf.autocapitalizationType = UITextAutocapitalizationTypeNone; //内容垂直对齐方式 继承自uicontrol中contentVerticalAlignment
tf.contentVerticalAlignment = UIControlContentHorizontalAlignmentCenter; //设置 提示字 文本框为空的时候显示 默认颜色为灰色
tf.placeholder = @"ccasdfjkdlajbasdf"; //设置 格式化提示字体
tf.attributedPlaceholder = attr; //设置是否在开始编辑的时候清空 文本框 默认为NO
tf.clearsOnBeginEditing = YES; //设置字体大小是否随宽度自适应 ,跟设置最小字体一起使用
tf.adjustsFontSizeToFitWidth = YES; //设置最小字体
tf.minimumFontSize = 10.0;
//设置背景图片 设置背景图片时图片会被拉伸 设置文本框边框会影响 图片显示
tf.background = [UIImage imageNamed:@"332.jpg"];
//设置文本框禁用时图片 边框不会影响
// tf.enabled = NO;
tf.disabledBackground = [UIImage imageNamed:@"223.jpg"]; //tf.editing 是否正在编辑
[self setValue:[NSNumber numberWithBool:YES] forKeyPath:@"tf.adjustsFontSizeToFitWidth"];
NSLog(@"%i",tf.isEnabled);
//allowsEditingTextAttributes 是否允许更改文本属性字典 默认为no
tf.allowsEditingTextAttributes = YES;
//设置字符属性字典 值修改了提示字的 格式 输入的文字怎没有变化
tf.typingAttributes = dic; //设置文本框清空按钮 显示状态
/*
UITextFieldViewModeNever 不显示 UITextFieldViewModeWhileEditing 当修改时 常用 UITextFieldViewModeUnlessEditing 非编辑状态显示 UITextFieldViewModeAlways 一直显示
*/
tf.clearButtonMode = UITextFieldViewModeWhileEditing; //添加文本框左右识图 默认显示状态为UITextFieldViewModeNever
tf.leftView = [UIView new];
tf.rightView = [UIView new];
//
/* 设置文本框左右视图 显示状态意思与清空按钮状态一样
tf.leftViewMode 修改左视图显示状态
tf.rightViewMode 修改右视图显示状态 UITextFieldViewModeNever 从不 UITextFieldViewModeWhileEditing 修改时 UITextFieldViewModeUnlessEditing 非修改时 UITextFieldViewModeAlways 一直
*/
//使用后键盘不出现
//设置当文本框成为第一响应者是弹出的视图 底部出现宽度默认为屏幕宽度 高度自定义 x,y,width 设置了都不管用
UIView * c = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 70)];
c.backgroundColor = [UIColor greenColor];
tf.inputView = c;
//设置文本框成为第一响应者弹出的辅助视图 出现在inputview上 于in普通View一样 只有高度发生了变化
UIView *fz = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 30, 50)];
fz.backgroundColor = [UIColor redColor];
tf.inputAccessoryView = fz;
//设置文本框 再次输入文本时(重新获取焦点)不允许插入文字
tf.clearsOnInsertion = YES;
//键盘类型
/*
UIKeyboardTypeDefault, 默认键盘,支持所有字符 UIKeyboardTypeASCIICapable, 支持ASCII的默认键盘 UIKeyboardTypeNumbersAndPunctuation, 标准电话键盘,支持+*#字符 UIKeyboardTypeURL, URL键盘,支持.com按钮 只支持URL字符 UIKeyboardTypeNumberPad, 数字键盘 UIKeyboardTypePhonePad, 电话键盘 UIKeyboardTypeNamePhonePad, 电话键盘,也支持输入人名 UIKeyboardTypeEmailAddress, 用于输入电子 邮件地址的键盘 UIKeyboardTypeDecimalPad, 数字键盘 有数字和小数点 UIKeyboardTypeTwitter, 优化的键盘,方便输入@、#字符 UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable,
*/
tf.keyboardType = UIKeyboardTypeTwitter; //设置键盘颜色
/*
UIKeyboardAppearanceDefault, 浅灰 UIKeyboardAppearanceDark 黑 UIKeyboardAppearanceLight 高亮 UIKeyboardAppearanceAlert = UIKeyboardAppearanceDark, 深灰
*/
tf.keyboardAppearance = UIKeyboardAppearanceLight; //设置键盘return键 成什么键
/*
UIReturnKeyDefault,
UIReturnKeyGo,
UIReturnKeyGoogle,
UIReturnKeyJoin,
UIReturnKeyNext,
UIReturnKeyRoute,
UIReturnKeySearch,
UIReturnKeySend,
UIReturnKeyYahoo,
UIReturnKeyDone,
UIReturnKeyEmergencyCall 紧急呼叫
UIReturnKeyContinue
*/
tf.returnKeyType = UIReturnKeyEmergencyCall; }
#pragma MARK: - 触屏失去焦点
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[super touchesBegan:touches withEvent:event];
//注销第一响应者 收回键盘
[tf endEditing:YES];
// [tf resignFirstResponder];
}
下面是代理方法的实现应用
头部UITextFieldDelegate协议 <UITextFieldDelegate>
遵守 协议
遵守协议 tf.delegate = self;
#pragma MARK: - UITextFiledDelegate 实现
//点击输入框输入该方法 返回yes进入编辑状态, no则不能编辑 每次获取焦点后触发
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
tf.text = @"我决定能不能让你编辑我~~~~~";
return YES;
}
//开始编辑时触发方法
- (void)textFieldDidBeginEditing:(UITextField *)textField{
NSLog(@"我不我就不,我要编辑了~~~~");
}
//将要结束编辑时调用方法, 返回YES结束 返回NO不能
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
NSLog(@"将要结束编辑 咯~~~~~~ 我返回yes就结束了,返回no 还得编瞎话~~");
return YES;
}
//结束编辑调用的方法
- (void)textFieldDidEndEditing:(UITextField *)textField{
NSLog(@"我现在真的结束了!!!!!");
}
//输入字符时调用的方法 返回yes允许输入 返回no不允许输入
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSLog(@"我输入了字符~~~输入咯哦~~");
return YES;
}
//点击清理按钮时触发的方法 返回yes清理 no 不清理
- (BOOL)textFieldShouldClear:(UITextField *)textField{
NSLog(@"就不清,就不清~~~~怎么样。。。。");
return YES;
}
//单击return 时触发的方法 yes执行 no不执行
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
NSLog(@"yes");
return YES;
}
今天倒腾了一下午整理了 一下textfield 的基本使用属性 UITextField联系到好多键盘的设置 后面还有关于重绘UITextField的之后再做补充
注意一些属性之间的相互冲突 今天碰到一个问题 当弄出屏幕键盘后我的 键盘打字上不去只能用屏幕键盘才能输入 , 当跳出inputview后 键盘就不在出现 这个东西不太明白有没有大神说一下
UITextField 基本属性使用的更多相关文章
- iOS学习笔记(5)— UITextField
UITextField详解 一.基本属性 1.创建文本输入框 UITextField*textField=[[UITextField alloc]initWithFrame:CGRectMake(10 ...
- UITextFeild的基本属性
textField 基本属性 _textField.frame = CGRectMake(0, 0, 200, 50); _textField.delegate = self; _textFiel ...
- UITextField
UITextFieldDemo 效果 特点 1.有效定制键盘的样式 2.处理键盘对文本框的遮挡 用法 1.导入文件(UITextField+CreateInputAccessoryView.h/.m) ...
- iOS学习-UITextField设置placeholder的颜色
UITextField *text = [[UITextField alloc] initWithFrame:CGRectMake(, , , )]; text.borderStyle = UITex ...
- 12. UITextField
1. UITextField 的认识 UItextField通常用于外部数据输入,以实现人机交互.比如我们QQ.微信的登录界面中让你输入账号和密码的地方 2. UITextField 控件的属性设置 ...
- 【修改 UITextField 中 placeholder 的顏色】
第一种方法: [textfeild setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"]; ...
- UI控件(UITextField)
@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UITextField* textField1 = ...
- jQuery插件:jqGrid引入及基本属性
1. jqGrid下载 jqGrid下载地址: http://www.trirand.com/blog/ jqGrid Demo: http://www.guriddo.net/demo/guridd ...
- Material Design 概念,环境和基本属性
Material Design 概念,环境和基本属性 Material Design是随Android 5.0推出的一种设计概念, 涉及到了跨平台和设备的视觉,动态,交互设计等方面. 设计概念 M ...
随机推荐
- [Shell] 读取脚本路径
以下是几种在 Shell 中读取路径的方法. 返回当前工作目录绝对路径 echo $(pwd) 返回 shell 第一个参数.如果被执行对象位于 PATH 路径中,则返回该对象绝对路径:否则返回被执行 ...
- Linux高级编程--06.进程概述
进程控制块 在Linux中,每个进程在内核中都有一个进程控制块(PCB)来维护进程相关的信息,它通常包含如下信息: 进程id.系统中每个进程有唯一的id,在C语言中用pid_t类型表示,其实就是一个非 ...
- WPF中多个RadioButton绑定到一个属性
如图样: 在View中: <RadioButton IsChecked="{Binding Option, Converter={cvt:EnumToBooleanConverter} ...
- Alwayson+Replication
本文将介绍如何实现Alwayson + Replication ,通过AlwaysOn实现Publication database的高可用性,使Publication database在failove ...
- Surface Shader
Surface Shader: (1)必须放在SubShdader块,不能放在Pass内部: (2)#pragma sufrace surfaceFunction lightModel [option ...
- Direct2D开发:绘制网格
转载请注明出处:http://www.cnblogs.com/Ray1024 一.引言 最近在使用Direct2D进行绘制工作中,需要实现使用Direct2D绘制网格的功能.在网上查了很多资料,终于实 ...
- sql server 调用webservice
sql server版本2008以上,应该都可以 更改服务器配置 sp_configure ; GO RECONFIGURE; GO sp_configure ; GO RECONFIGURE; GO ...
- UPW学习资料整理 .NET C# 转
开发工具下载https://www.visualstudio.com/?Wt.mc_id=DX_MVP5000319 Windows 10 UWP开发视频1http://blogs.windows.c ...
- ASP.NET MVC权限验证 封装类
写该权限类主要目地 为了让权限配置更加的灵活,可以根据SQL.json.或者XML的方式来动态进行页面的访问控制,以及没有权限的相关跳转. 使用步骤 1.要建一个全局过滤器 //受权过滤器 publi ...
- IOS开发UI基础UITableView的属性
UITableView UITableView内置了两种样式:UITableViewStylePlain,UITableViewStyleGrouped <UITableViewDataSour ...