UITextField的使用总结
初始化一个文字框:
UITextField * textField = [[UITextField alloc]initWithFrame:CGRectMake(, , , )];
设置和获取文字框文字:
@property(nonatomic,copy) NSString *text;
通过AttributedString创建和获取文字:
@property(nonatomic,copy) NSAttributedString *attributedText;
设置字体颜色属性:
@property(nonatomic,retain) UIColor *textColor;
设置字体属性:
@property(nonatomic,retain) UIFont *font;
设置字体对齐格式:
@property(nonatomic)NSTextAlignment textAlignment;
设置输入框风格:
@property(nonatomic) UITextBorderStyle borderStyle;
这个风格是一个枚举,如下:
typedef NS_ENUM(NSInteger, UITextBorderStyle) {
//没有任何边框
UITextBorderStyleNone,
//线性边框
UITextBorderStyleLine,
//阴影效果边框
UITextBorderStyleBezel,
//原型效果边框
UITextBorderStyleRoundedRect
};
设置默认字体属性
@property(nonatomic,copy) NSDictionary *defaultTextAttributes;
这个属性的设置会影响到全部字体的属性。
设置缺省时显示的灰度字符串
@property(nonatomic,copy) NSString *placeholder;
通过AttributedString设置缺省字符串
@property(nonatomic,copy) NSAttributedString *attributedPlaceholder;
设置是否在开始编辑时清空输入框内容
@property(nonatomic) BOOL clearsOnBeginEditing;
设置字体大小是否随宽度自适应(默认为NO)
@property(nonatomic) BOOL adjustsFontSizeToFitWidth;
设置最小字体大小
@property(nonatomic) CGFloat minimumFontSize;
设置背景图片(会被拉伸)
@property(nonatomic,retain) UIImage *background;
设置禁用时的背景图片
@property(nonatomic,retain) UIImage *disabledBackground;
是否正在编辑(只读属性)
@property(nonatomic,readonly,getter=isEditing) BOOL editing;
是否允许更改字符属性字典
@property(nonatomic) BOOL allowsEditingTextAttributes;
设置属性字典
@property(nonatomic,copy) NSDictionary *typingAttributes;
设置清除按钮的显示模式
@property(nonatomic) UITextFieldViewMode clearButtonMode;
这是一个枚举,如下:
typedef NS_ENUM(NSInteger, UITextFieldViewMode) {
//从不显示
UITextFieldViewModeNever,
//编辑的时候显示
UITextFieldViewModeWhileEditing,
//非编辑的时候显示
UITextFieldViewModeUnlessEditing,
//任何时候都显示
UITextFieldViewModeAlways
};
设置输入框左边的view
@property(nonatomic,retain) UIView *leftView;
设置输入框左视图的显示模式
@property(nonatomic) UITextFieldViewMode leftViewMode;
设置输入框右边的view
@property(nonatomic,retain) UIView *rightView;
设置输入框右视图的显示模式
@property(nonatomic) UITextFieldViewMode rightViewMode;
设置输入框成为第一响应时弹出的视图和辅助视图(类似键盘)
@property (readwrite, retain) UIView *inputView;
@property (readwrite, retain) UIView *inputAccessoryView;
这个属性设置是否允许再次编辑时在内容中间插入内容
@property(nonatomic) BOOL clearsOnInsertion;
注销第一响应(収键盘)
- (BOOL)endEditing:(BOOL)force;
UITextFieldDelegate 代理中的方法
点击输入框时触发的方法,返回YES则可以进入编辑状态,NO则不能。
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;
开始编辑时调用的方法
- (void)textFieldDidBeginEditing:(UITextField *)textField;
将要结束编辑时调用的方法,返回YES则可以结束编辑状态,NO则不能
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField;
结束编辑调用的方法
- (void)textFieldDidEndEditing:(UITextField *)textField;
输入字符时调用的方法
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
点击清除按钮时调用的函数,返回YES则可以清除,点击NO则不能清除
- (BOOL)textFieldShouldClear:(UITextField *)textField;
点击return键触发的函数
UITextField的使用总结的更多相关文章
- 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 = ...
- UITextField的代理方法:textField:shouldChangeCharactersInRange:replacementString
原文链接:http://www.cnblogs.com/zhanggui/p/6101813.html 这个我在开发的过程中用到的次数最多,因此这里就简单对其进行分析.先看看Command+点击 弹出 ...
- iOS开发中设置UITextField的占位文字的颜色,和光标的颜色
在iOS开发中,对于很多初学者而言,很有可能碰到需要修改UITextField的占位文字的颜色,以及当UITextField成为第一响应者后光标的颜色,那么下面小编就介绍一下修改占位文字和光标的颜色. ...
- iOS UITextField限制输入数字
有时候项目中要求文本框中只能输入数字,如:价格.公里数.费用等等,一般的文本框不限制输入的格式,这时候只能强制限制输入框的输入格式了,代码如下: #import "ViewControlle ...
- UITextField常用属性归纳:文本框样式、文字样式、键盘样式、左右视图样式、清除按钮设置等
(1)可以根据需要设置文本框的样式(包括形状.边框颜色.背景等). (2)可以根据需要设置文字显示样式(包括输入密码时的密文显示.文字横向居中.纵向居中上下.输入的文字是否首席木大写.文字超过后是否缩 ...
- UITextField使用详解
转iOS中UITextField使用详解 (1) //初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFr ...
随机推荐
- 《React-Native系列》3、RN与native交互之Callback、Promise
接着上一篇<React-Native系列>RN与native交互与数据传递,我们接下来研究另外的两种RN与Native交互的机制 一.Callback机制 首先Calllback是异步的, ...
- 获取微信公众号用户的基本信息(UnionID机制)
获取用户基本信息(UnionID机制) 在关注者与公众号产生消息交互后,公众号可获得关注者的OpenID(加密后的微信号,每个用户对每个公众号的OpenID是唯一的.对于不同公众号,同一用户的open ...
- Javascript -- 级联菜单, javascript解析xml文件
1. cities.xml 保存省份和城市 <?xml version="1.0" encoding="GB2312"?> <china> ...
- org.apache.log4j.Logger用法
在应用程序中添加日志记录总的来说基于三个目的 :监视代码中变量的变化情况,周期性的记录到文件中供其他应用进行统计分析工作:跟踪代码运行时轨迹,作为日后审计的依据:担当集成开发环境中的调试器的作用,向文 ...
- Redis_01
http://redis.io/ http://www.yiibai.com/redis/redis_quick_guide.html X
- selenium学习笔记(简单的元素定位)
收拾一下心情开始新的一周工作 继续是selenium的学习.配置成功后 由于所有操作都是建立在页面元素基础上的.所以下来就是学习定位元素 首先是基础的定位.就使用博客园首页搜索框为例: 下面是代码: ...
- ubuntu14.04搭建Hadoop2.9.0集群(分布式)环境
本文进行操作的虚拟机是在伪分布式配置的基础上进行的,具体配置本文不再赘述,请参考本人博文:ubuntu14.04搭建Hadoop2.9.0伪分布式环境 本文主要参考 给力星的博文——Hadoop集群安 ...
- webpack相关文章
0.https://doc.webpack-china.org/concepts/ (webpack中文文档) 1.https://segmentfault.com/a/119000000617877 ...
- LeetCode OJ:Spiral MatrixII(螺旋矩阵II)
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For ...
- LeetCode OJ:Binary Tree Maximum Path Sum(二叉树最大路径和)
Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence ...