iOS UI基础 - 20 UITextField
//找到已经创建好的UITextField
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(, , RFSCREEN_W - , )];
textField.leftImageName = @"login_user_icon"
//设置边框样式
textField.borderStyle = UITextBorderStyleNone;
//通过layer设置圆角
//textField.layer.cornerRadius = 10;
textField.layer.borderColor = Color_White.CGColor;
textField.layer.borderWidth = ;
// 设置字体颜色
textField.textColor = Color_White;
// 输入框中是否有个叉号,在什么时候显示,用于一次性删除输入框中的内容
textField.clearButtonMode = UITextFieldViewModeAlways;
//第一响应者,一个界面可能有多个可输入的控件,哪一个正在编辑哪一个就是第一响应者
[textField becomeFirstResponder];
// 设置左边图标
UIImageView *leftImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_user_icon"]];
leftImageView.frame = CGRectMake(, , , );
leftImageView.contentMode = UIViewContentModeCenter;
textField.leftView = leftImageView;
//设置左视图的显示模式
textField.leftViewMode = UITextFieldViewModeAlways;
// 设置键盘的样式
textField.keyboardType = UIKeyboardTypeNumberPad;
// 设置占位文字
textField.placeholder = @"请输入用户名";
// 设置占位文字的颜色
[textField setValue:Color_White forKeyPath:@"placeholderLabel.textColor"]; [self.view addSubview:textField];
限定只可以输入数字和6位长度
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString *text = [textField text];
NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789\b"];
string = [string stringByReplacingOccurrencesOfString:@" " withString:@""];
if ([string rangeOfCharacterFromSet:[characterSet invertedSet]].location != NSNotFound) {
return NO;
}
text = [text stringByReplacingCharactersInRange:range withString:string];
text = [text stringByReplacingOccurrencesOfString:@" " withString:@""]; if ([text stringByReplacingOccurrencesOfString:@" " withString:@""].length >= ) {
return NO;
} [textField setText:text];
_confirmButton.enabled = text.length > ? YES : NO;
return NO;
}
iOS UI基础 - 20 UITextField的更多相关文章
- iOS UI基础-4.0应用程序管理
功能与界面 功能分析: 以九宫格的形式展示应用信息 点击下载按钮后,做出相应的操作 步骤分析: 加载应用信息 根据应用的个数创建对应的view 监听下载按钮点击 整个应用界面: 程序实现 思路 UI布 ...
- iOS UI基础-1.0加法计算器
1.打开Xcode,新建一个项目 2.Single View Application是最适合初学者的模板 3.填写该应用相关信息 4.搭建UI界面 项目创建完毕后,自动帮我们做了很多配置,也自动生成了 ...
- UI基础之UITextField相关
UITextField *textF = [[UITextField alloc] init]; 1.字体相关 textF.text = @"文本框文字"; textF.textC ...
- iOS UI基础-17.0 UILable之NSMutableAttributedString
在iOS开发中,常常会有一段文字显示不同的颜色和字体,或者给某几个文字加删除线或下划线的需求.之前在网上找了一些资料,有的是重绘UILabel的textLayer,有的是用html5实现的,都比较麻烦 ...
- iOS UI基础-13.0 数据存储
应用沙盒 每个iOS应用都有自己的应用沙盒(应用沙盒就是文件系统目录),与其他文件系统隔离.应用必须待在自己的沙盒里,其他应用不能访问该沙盒 应用沙盒的文件系统目录,如下图所示(假设应用的名称叫Lay ...
- iOS UI基础-10.0 QQ聊天布局之键盘及文本使用
要实现的效果: 这里只说用到的几个知识点 1.图片包含文字 在设置文字的Frame的时候,使用背景(按钮)的尺寸,文字使用了内边距 背景图片,使用拉伸 /** * 返回一张可以随意拉伸不变形的图片 ...
- iOS UI基础-9.0 UITableView基础
在iOS中,要实现表格数据展示,最常用的做法就是使用UITableView.UITableView继承自UIScrollView,因此支持垂直滚动,而且性能极佳. UITableView有两种样式: ...
- iOS UI基础-6.0 UIActionSheet的使用
UIActionSheet是在iOS弹出的选择按钮项,可以添加多项,并为每项添加点击事件. 使用 1.需要实现UIActionSheetDelegate 协议 @interface NJWisdom ...
- iOS UI基础-4.2应用程序管理 Xib文件使用
Xib调整使用 1.新建xib文件 New File-->User Interface-->Empty 2.打开新建的xib文件,出现可视化窗口 (1)拖入一个UIView (不是UIVi ...
随机推荐
- F#周报2018年第51期
新闻 有经验的开发者选择F# 2018年10佳技术讲话 试用F#开发WebAssembly Fable.Remoting: 刷新访问令牌 F#开发WebAssembly现在可以使用代码补全 Rider ...
- mysql的多表查询join
http://blog.csdn.net/jintao_ma/article/details/51260458 https://zhidao.baidu.com/question/1304158100 ...
- [No0000C4]TortoiseSVN配置外部对比工具
TortoiseSVN -> Settings Diff Viewer : 选中External->找到外部工具:如BCompare.路径如果有空格的最好用"双引号"括 ...
- tensorflow的assgin方法
官网API是这么说的 This operation outputs a Tensor that holds the new value of 'ref' after the value has bee ...
- 自动化运维工具-mussh工具安装配置及简单使用讲解
1.先决条件: 安装pssh工具的主机针对远程主机需要配置免秘钥认证: ssh-keygen -t rsa ssh-copy-id [remotehost] 2.下载mussh工具安装介质: http ...
- [daily][archlinux][pacman] 删除所有孤立包(orphan)
[:] <tong> sudo pacman -Rsun `pacman -Qdt |cut -d` [:] <tong> 我每次都这么删, 有没有高级点的 ...
- 【Mysql数据库访问利器】phpMyadmin
缘由 我们程序员难免要和数据库打交道,经过这几年的锻炼,感觉手写SQL语句已经忘记的差不错了,促使我一定要这篇文章的原因是,有一次晚上我更新某个系统的数据库的表(由于目前公司比较严格,数据库都只能通过 ...
- 转:ORACLE 中ROWNUM用法总结!
oracle 分页查询语句:select * from (select u.*,rownum r from (select * from userifno) u where rownum<大值) ...
- 《Mysql 字符集》
一:什么是字符集呢? - 引用书中的例子:同样是大熊猫,在大陆叫熊猫,在台湾叫猫熊,在美国叫Panda,要到了非洲,可能都不知道叫啥(于是就乱码了). - 在例子之后引入字符集的概念:字符集就是指符号 ...
- linux read()和write
参考http://www.cnblogs.com/xiehongfeng100/p/4619451.html 1. read总是在接收缓冲区有数据时立即返回,而不是等到给定的read buffer填满 ...