textField 基本属性
_textField.frame = CGRectMake(0, 0, 200, 50);
_textField.delegate = self;
_textField.text = str;
[_textField becomeFirstResponder];
/*
设置背景色、背景图片。设置了背景图片后,背景色设置无效
如果background为nil,disabledBackground无效
*/
_textField.background = [UIImage imageNamed:@"返回-按下"];
_textField.disabledBackground = [UIImage imageNamed:@"返回-未激活"];
// _textField.enabled = NO;
_textField.backgroundColor = [UIColor blueColor];
_textField.placeholder = @"输入文本…";
/*
设置为YES时文本会自动缩小以适应文本窗口大小.默认是保持原来大小,而让长文本滚动
*/
_textField.adjustsFontSizeToFitWidth = YES;
//设置自动缩小显示的最小字体大小,adjustsFontSizeToFitWidth为YES才会起作用
_textField.minimumFontSize = 20;
_textField.font = [UIFont systemFontOfSize:30.0f];
/*
内容对齐方式
内容的垂直对齐方式 UITextField继承自UIControl,此类中有一个属性contentVerticalAlignment
*/
_textField.textAlignment = UITextAlignmentLeft;
_textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
/*
typedef enum {
UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect
} UITextBorderStyle;
*/
_textField.borderStyle = UITextBorderStyleBezel;
/*
每输入一个字符就变成点 用语密码输入
*/
_textField.secureTextEntry = NO;
/*
//输入框中是否有个叉号,在什么时候显示,用于一次性删除输入框中的内容
typedef enum {
UITextFieldViewModeNever, 重不出现
UITextFieldViewModeWhileEditing, 编辑时出现
UITextFieldViewModeUnlessEditing, 除了编辑外都出现
UITextFieldViewModeAlways 一直出现
} UITextFieldViewMode;
*/
_textField.clearButtonMode = UITextFieldViewModeWhileEditing;
/*
开始编辑,清空数据
*/
_textField.clearsOnBeginEditing = NO;
/*
//是否纠错
typedef enum {
UITextAutocorrectionTypeDefault, 默认
UITextAutocorrectionTypeNo, 不自动纠错
UITextAutocorrectionTypeYes, 自动纠错
} UITextAutocorrectionType;
*/
_textField.autocorrectionType = UITextAutocorrectionTypeYes;
/*
//首字母是否大写
typedef enum {
UITextAutocapitalizationTypeNone, 不自动大写
UITextAutocapitalizationTypeWords, 单词首字母大写
UITextAutocapitalizationTypeSentences, 句子的首字母大写
UITextAutocapitalizationTypeAllCharacters, 所有字母都大写
} UITextAutocapitalizationType;
*/
_textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
/*
键盘
typedef enum {
UIKeyboardTypeDefault, 默认键盘,支持所有字符
UIKeyboardTypeASCIICapable, 支持ASCII的默认键盘
UIKeyboardTypeNumbersAndPunctuation, 标准电话键盘,支持+*#字符
UIKeyboardTypeURL, URL键盘,支持.com按钮 只支持URL字符
UIKeyboardTypeNumberPad, 数字键盘
UIKeyboardTypePhonePad, 电话键盘
UIKeyboardTypeNamePhonePad, 电话键盘,也支持输入人名
UIKeyboardTypeEmailAddress, 用于输入电子 邮件地址的键盘
UIKeyboardTypeDecimalPad, 数字键盘 有数字和小数点
UIKeyboardTypeTwitter, 优化的键盘,方便输入@、#字符
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable,
} UIKeyboardType;
*/
_textField.keyboardType = UIKeyboardTypeDefault;
/*
//return键变成什么键
typedef enum {
UIReturnKeyDefault, 默认 灰色按钮,标有Return
UIReturnKeyGo, 标有Go的蓝色按钮
UIReturnKeyGoogle,标有Google的蓝色按钮,用语搜索
UIReturnKeyJoin,标有Join的蓝色按钮
UIReturnKeyNext,标有Next的蓝色按钮
UIReturnKeyRoute,标有Route的蓝色按钮
UIReturnKeySearch,标有Search的蓝色按钮
UIReturnKeySend,标有Send的蓝色按钮
UIReturnKeyYahoo,标有Yahoo的蓝色按钮
UIReturnKeyYahoo,标有Yahoo的蓝色按钮
UIReturnKeyEmergencyCall, 紧急呼叫按钮
} UIReturnKeyType;
*/
_textField.returnKeyType = UIReturnKeyDone;
/*
//键盘外观
typedef enum {
UIKeyboardAppearanceDefault, 默认外观,浅灰色
UIKeyboardAppearanceDark, 深灰 石墨色
UIKeyboardAppearanceLight 浅灰色
} UIReturnKeyType;
*/
_textField.keyboardAppearance=UIKeyboardAppearanceDefault;
/*
设置左右的两个view
*/
// UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image_right"]];
// imgView.frame = CGRectMake(0, 0, 20, 20);
// _textField.rightView = imgView;
// _textField.rightViewMode = UITextFieldViewModeAlways; // 同上
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image_left"]];
imgView.frame = CGRectMake(0, 0, 20, 20);
_textField.leftView = imgView;
_textField.leftViewMode = UITextFieldViewModeAlways; // 同上
/*
重写绘制行为
除了UITextField对象的风格选项,你还可以定制化UITextField对象,为他添加许多不同的重写方法,来改变文本字段的显示行为。这些方法都会返回一个CGRect结构,制定了文本字段每个部件的边界范围。以下方法都可以重写。
– textRectForBounds: //重写来重置文字区域
– drawTextInRect: //改变绘文字属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了.
– placeholderRectForBounds: //重写来重置占位符区域
– drawPlaceholderInRect: //重写改变绘制占位符属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了.
– borderRectForBounds: //重写来重置边缘区域
– editingRectForBounds: //重写来重置编辑区域
– clearButtonRectForBounds: //重写来重置clearButton位置,改变size可能导致button的图片失真
– leftViewRectForBounds:
– rightViewRectForBounds:
*/
textField 基本属性的更多相关文章
- UITextFeild的基本属性
textField 基本属性 _textField.frame = CGRectMake(0, 0, 200, 50); _textField.delegate = self; _textFiel ...
- Flutter TextField 文本输入框的基本属性及详解
TextField 文本输入框 源码分析: const TextField({ Key key, this.controller, // 控制正在编辑文本 this.focusNode, // 获取键 ...
- TextField和TextView的限制输入长度
TextField的限制代理方法 只需要在这个代理方法里面code这样的代码就可以了 16 是长度可以自己设置 - (BOOL)textField:(UITextField *)textField s ...
- 控制TextField的内容长度
参考如下代码(下例是控制设置交易密码,控制6位): - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [ ...
- jQuery插件:jqGrid引入及基本属性
1. jqGrid下载 jqGrid下载地址: http://www.trirand.com/blog/ jqGrid Demo: http://www.guriddo.net/demo/guridd ...
- iOS 如何自定义UISearchBar 中textField的高度
iOS 如何自定义UISearchBar 中textField的高度 只需设置下边的方法就可以 [_searchBar setSearchFieldBackgroundImage:[UIImage i ...
- iOS 点击TextField不弹出软键盘的解决方案
开发中遇到: 在模拟器里面,textfield可以通过电脑键盘输入,可是怎么也不会自动弹出模拟器软键盘 解决方案: 切换一下键盘,command+shift+k,Xcode6.3 中只能是一种输入源
- Material Design 概念,环境和基本属性
Material Design 概念,环境和基本属性 Material Design是随Android 5.0推出的一种设计概念, 涉及到了跨平台和设备的视觉,动态,交互设计等方面. 设计概念 M ...
- UITextField的代理方法:textField:shouldChangeCharactersInRange:replacementString
原文链接:http://www.cnblogs.com/zhanggui/p/6101813.html 这个我在开发的过程中用到的次数最多,因此这里就简单对其进行分析.先看看Command+点击 弹出 ...
随机推荐
- 删除C代码中的注释行【状态机】
今天在学ruby时遇到的一个经典的题目,一直都知道但从来没有实现过.呈上状态机,代码略.(写代码的时候还是需要注意一些小情况的)
- 项目启动报错:Communications link failure
2017-12-29 10:43:19,776 ERROR [com.alibaba.druid.pool.DruidDataSource] - <init datasource error, ...
- 区块链技术核心概念与原理讲解-Tiny熊
转载自简书ceido:https://www.jianshu.com/u/fcdf49ef65bb (1)区块链前世今生 密码朋克(Cypherpunk):是一个邮件组,里面有许多大牛. 区块链不是单 ...
- python矩阵运算大全(linalg模块)
python矩阵的运算大全 python矩阵运算可以用numpy模块,也可以用scipy模块,主要运算包括以下几种: #1-1python矩阵运算所需模块 import numpy as npimpo ...
- CheckBox标签和属性
CheckBox的作用:可以提供复选 下面是我点击按钮查看所选内容的代码:定义按钮监听器,并在onClick方法中调用shoeAlt方法(此方法会在第二块代码定义) Button btn=(Butto ...
- Spring入门之三-------SpringIoC之Scopes
一.singleton和prototype public class Bean1 { public Bean1() { System.out.println(this.getClass().getSi ...
- jQuery通过name获取值
使用jQuery获取name="day"的input对象: 方法1 var dayObj=$('input[name="day"]'); for(int i=0 ...
- Emacs: 设置窗口标题格式
Emacs默认的窗口标题常常比较简单,例如我的默认标题是"emacs@ubuntu".如果想要在标题中显示更多的信息,我们可以对它进行一些设置.由于Emacs的可扩展性,这种修改实 ...
- 六十一、SAP中的逻辑运算与进制转换
一.代码如下 二.16进制计算过程如下 三.计算结果为16进制的11,也就是10进制的17
- js基础学习之-js全局对象
声明的三种方式: 第一种: var test; //或var test = 5; 第二种: test = 5; 第三种: window.test; //或window.test = 5; //只是使用 ...