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 ...
随机推荐
- Knockout 新版应用开发教程之Observable Arrays
假如你想到侦测和相应一个对象的改变,假如你想要侦测和响应一一组合集的改变,就要用observableArray 在许多场景都是很有用的,比如你要在UI上需要显示/编辑的一个列表数据集合,然后对集合进行 ...
- 整合ssh model $$_javassist_13 cannot be cast to javassist.util.proxy.Proxy
经goole stackoverflow 发现是 javassit 包冲突 项目使用的是maven 检查依赖包
- 斜堆(二)之 C++的实现
概要 上一章介绍了斜堆的基本概念,并通过C语言实现了斜堆.本章是斜堆的C++实现. 目录1. 斜堆的介绍2. 斜堆的基本操作3. 斜堆的C++实现(完整源码)4. 斜堆的C++测试程序 转载请注明出处 ...
- 剑指架构师系列-Hibernate需要掌握的Annotation
1.一对多的关系配置 @Entity @Table(name = "t_order") public class Order { @Id @GeneratedValue priva ...
- [转载]SharePoint 2013搜索爬外网配置
本文介绍SharePoint 2013 设置外网(Internet)爬网源: 下面是步聚: 1. 新建外部爬网源 a. 打开 “SharePoint 2013 Central Administrati ...
- ASP.NET中WebService的两种身份验证方法
一.通过SOAP Header身份验证 此方法是通过设置SOAP Header信息来验证身份,主要通过以下几步: 1.在服务端实现一个SOAP Header类 public class Credent ...
- CMD魔法堂:CMD进入指定目录
一.前言 每次打开cmd默认目录总是当前用户目录,然后是一大轮cd命令才进入工作目录,哎,怎一个烦自了得.幸好我们可以通过批处理文件来进入指定目录,省心多了. 二.cmd命令介绍 CMD [/A ...
- Spring重点—— IOC 容器中 Bean 的生命周期
一.理解 Bean 的生命周期,对学习 Spring 的整个运行流程有极大的帮助. 二.在 IOC 容器中,Bean 的生命周期由 Spring IOC 容器进行管理. 三.在没有添加后置处理器的情况 ...
- 利用DropDownList实现下拉
在视图的Model<Vo>里面我们需要使用IEnumerable来将别的列表的数据全部的转化为下拉列表.下面是关于在项目中实际的写法. 一:实现下拉属性列表的写法 通过使用Select ...
- LeetCode127:Word Ladder II
题目: Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) ...