//设置文本框 透明度
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 基本属性使用的更多相关文章

  1. iOS学习笔记(5)— UITextField

    UITextField详解 一.基本属性 1.创建文本输入框 UITextField*textField=[[UITextField alloc]initWithFrame:CGRectMake(10 ...

  2. UITextFeild的基本属性

    textField 基本属性   _textField.frame = CGRectMake(0, 0, 200, 50); _textField.delegate = self; _textFiel ...

  3. UITextField

    UITextFieldDemo 效果 特点 1.有效定制键盘的样式 2.处理键盘对文本框的遮挡 用法 1.导入文件(UITextField+CreateInputAccessoryView.h/.m) ...

  4. iOS学习-UITextField设置placeholder的颜色

    UITextField *text = [[UITextField alloc] initWithFrame:CGRectMake(, , , )]; text.borderStyle = UITex ...

  5. 12. UITextField

    1. UITextField 的认识 UItextField通常用于外部数据输入,以实现人机交互.比如我们QQ.微信的登录界面中让你输入账号和密码的地方 2. UITextField 控件的属性设置 ...

  6. 【修改 UITextField 中 placeholder 的顏色】

    第一种方法: [textfeild setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"]; ...

  7. UI控件(UITextField)

    @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UITextField* textField1 = ...

  8. jQuery插件:jqGrid引入及基本属性

    1. jqGrid下载 jqGrid下载地址: http://www.trirand.com/blog/ jqGrid Demo: http://www.guriddo.net/demo/guridd ...

  9. Material Design 概念,环境和基本属性

    Material Design 概念,环境和基本属性 Material Design是随Android 5.0推出的一种设计概念, 涉及到了跨平台和设备的视觉,动态,交互设计等方面.   设计概念 M ...

随机推荐

  1. Popup 显示阴影

    WPF Popup: How to put a border around the popup? 通过设置 Border 的 margin 来为阴影留出位置,并设置 Popup: AllowsTran ...

  2. Apache+tomcat+mod_jk+centos6.2负载均衡集群配置--转载

    转载地址:http://blog.163.com/chenhui_java/blog/static/17267249420128101191860/ 注: 由于长期受转载毒害,所以本人日志均是原创:其 ...

  3. 堆表和%%lockres%%函数

    在今天的文章里,我想向你展示下SQL Server里一个未公开的函数,还有你如何用那个函数来找出在哪页记录被存储. %%lockres%% 今天我想向你展示的未公开函数叫做%%lockres%%,它与 ...

  4. 【第二课】深入理解Handler

    简要讲解Handler是做什么的 我们知道,在Android中,app启动会启动一个进程一个线程——UI线程,UI线程是主线程,并且不允许这个线程阻塞超过5秒,一旦超过5秒就会ANR. 所以较为耗时的 ...

  5. Sprint第三个冲刺(第四天)

    一.Sprint介绍 任务进度: 二.Sprint周期 看板: 燃尽图:

  6. ok6410 android driver(10)

    From this essay, we go to a new discussion "Android Hardware Abstraction Layer". In this e ...

  7. HTML--Table布局

    <DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" Content= ...

  8. Windows 8.1 去掉库的方法

    Windows 8.1[这台电脑],  里面又多了[文件夹]分类,真是各种不习惯 删除方法: 打开注册表, 找到 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Wind ...

  9. Winform开发框架之客户关系管理系统(CRM)的开发总结系列3-客户分类和配置管理实现

    我在本系列随笔的开始,介绍了CRM系统一个重要的客户分类的展示界面,其中包含了从字典中加载分类.从已有数据中加载分类.以及分组列表中加载分类等方式的实现,以及可以动态对这些节点进行配置,实现客户分类的 ...

  10. 精进不休 .NET 4.5 (12) - ADO.NET Entity Framework 6.0 新特性, WCF Data Services 5.6 新特性

    [索引页][源码下载] 精进不休 .NET 4.5 (12) - ADO.NET Entity Framework 6.0 新特性, WCF Data Services 5.6 新特性 作者:weba ...