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 ...
随机推荐
- python图片文字识别笔记
我的环境为python3 坑比较多,在此做记录,以备查阅 命令行安装: pip install PIL pip install pytesseract pip install Pillow 下载tes ...
- codeforces 808D
题意:给出一个序列,询问是否能移动一个数(或不操作)使得序列能分为左右两个和相等的子序列. 思路:对每个数处理最左边和最右边出现的位置.设置断点分左右区间,左右区间和差值的一半就是要找的数,进行判断. ...
- 洛谷P4311 士兵占领
题目描述 有一个M * N的棋盘,有的格子是障碍.现在你要选择一些格子来放置一些士兵,一个格子里最多可以放置一个士兵,障碍格里不能放置士兵.我们称这些士兵占领了整个棋盘当满足第i行至少放置了Li个士兵 ...
- bower安装使用、git安装、node安装、weui安装开发
bower安装使用以及git安装 bower需要:node 和 git 1.Git安装:(选择第二项:Use Git from the Windows Command Prompt)2.node安装: ...
- C++转C#函数事例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...
- php超级全局变量和魔术变量
php超级全局变量和魔术变量 一.总结 一句话总结: 1.两者的书写形式非常不一样,超级全局变量是$_大写变量名 的形式,魔术变量是 __大写变量名的形式__ 2.两者的应用范围不一样,超级全局变量是 ...
- 【Python那些事儿之十】range()和xrange()
by Harrison Feng in Python 无论是range()还是xrange()都是Python里的内置函数.这个两个内置函数最常用在for循环中.例如: >>> fo ...
- yii2:oracle date类型字段的写入或查询
insert: insert into tabname(datecol) value(sysdate) ; -- 用date值 insert into tabname(datecol) value(s ...
- C++中GB2312字符串和UTF-8之间的转换
在编程过程中需要对字符串进行不同的转换,特别是Gb2312和Utf-8直接的转换.在几个开源的魔兽私服中,很多都是老外开发的,而暴雪为了能 够兼容世界上的各个字符集也使用了UTF-8.在中国使用VS( ...
- Asp.net使用powershell管理hyper-v
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...