//找到已经创建好的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的更多相关文章

  1. iOS UI基础-4.0应用程序管理

    功能与界面 功能分析: 以九宫格的形式展示应用信息 点击下载按钮后,做出相应的操作 步骤分析: 加载应用信息 根据应用的个数创建对应的view 监听下载按钮点击 整个应用界面: 程序实现 思路 UI布 ...

  2. iOS UI基础-1.0加法计算器

    1.打开Xcode,新建一个项目 2.Single View Application是最适合初学者的模板 3.填写该应用相关信息 4.搭建UI界面 项目创建完毕后,自动帮我们做了很多配置,也自动生成了 ...

  3. UI基础之UITextField相关

    UITextField *textF = [[UITextField alloc] init]; 1.字体相关 textF.text = @"文本框文字"; textF.textC ...

  4. iOS UI基础-17.0 UILable之NSMutableAttributedString

    在iOS开发中,常常会有一段文字显示不同的颜色和字体,或者给某几个文字加删除线或下划线的需求.之前在网上找了一些资料,有的是重绘UILabel的textLayer,有的是用html5实现的,都比较麻烦 ...

  5. iOS UI基础-13.0 数据存储

    应用沙盒 每个iOS应用都有自己的应用沙盒(应用沙盒就是文件系统目录),与其他文件系统隔离.应用必须待在自己的沙盒里,其他应用不能访问该沙盒 应用沙盒的文件系统目录,如下图所示(假设应用的名称叫Lay ...

  6. iOS UI基础-10.0 QQ聊天布局之键盘及文本使用

    要实现的效果:   这里只说用到的几个知识点 1.图片包含文字 在设置文字的Frame的时候,使用背景(按钮)的尺寸,文字使用了内边距 背景图片,使用拉伸 /** * 返回一张可以随意拉伸不变形的图片 ...

  7. iOS UI基础-9.0 UITableView基础

    在iOS中,要实现表格数据展示,最常用的做法就是使用UITableView.UITableView继承自UIScrollView,因此支持垂直滚动,而且性能极佳. UITableView有两种样式: ...

  8. iOS UI基础-6.0 UIActionSheet的使用

    UIActionSheet是在iOS弹出的选择按钮项,可以添加多项,并为每项添加点击事件. 使用 1.需要实现UIActionSheetDelegate  协议 @interface NJWisdom ...

  9. iOS UI基础-4.2应用程序管理 Xib文件使用

    Xib调整使用 1.新建xib文件 New File-->User Interface-->Empty 2.打开新建的xib文件,出现可视化窗口 (1)拖入一个UIView (不是UIVi ...

随机推荐

  1. python中的过滤fliter

    movie_people = ['sb_alex', 'sb_wupeiqi', 'hello'] def filter_test(array): ret = [] for p in array: i ...

  2. Gym - 101375H MaratonIME gets candies 交互题

    交互题介绍:https://loj.ac/problem/6 题意:输出Q X ,读入><= 来猜数,小于50步猜出就算过样例 题解:根本不需要每次输出要打cout.flush()... ...

  3. windows Git Bash 无法运行python解决方法

    以前运行cmd命令都是在cmd里面的,但是那个页面实在是太丑了,后面我就全部用git bash来运行window下的命令了. 但是在git bash 中运行下python – -version 或 p ...

  4. C# Winform同一子窗体只允许打开一次

    在winform中一个窗口可以一直打开,是不合理的,解决方法: http://blog.csdn.net/kangkang621/article/details/49664295

  5. [administrative][CentOS][NetworkManager] networkmanager (二)

    [administrative][CentOS][NetworkManager] 万恶的NetworkManager到底怎么用 工程文档: https://wiki.gnome.org/Project ...

  6. Scaleform Gfx的Demo

    转载:http://www.xuebuyuan.com/2167614.html 新建一个Demo工程时,编译之前有一些VS的配置是必须的,在Debug和Release下,工程必须包括: $(GFXS ...

  7. 使用eclipse自动生成WSDL客户端代码

    一.获取WSDL文件 从网上可以搜到一些提供各种服务的免费接口,比如获取天气预报的接口: http://www.webxml.com.cn/WebServices/WeatherWebService. ...

  8. Mysql 通过information_schema爆库,爆表,爆字段

    MySQL版本大于5.0时,有个默认数据库information_schema,里面存放着所有数据库的信息(比如表名. 列名.对应权限等),通过这个数据库,我们就可以跨库查询,爆表爆列. 若要从这些视 ...

  9. 前端 HTML form表单标签 input标签 type属性 checkbox 多选框

    多选框 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...

  10. jenkins+maven+gitlab触发构建

    1.安装插件 安装gitlab插件 回到项目配置在“构建触发器”那里有一个Build when a change is pushed to GitLab. GitLab webhook选项复制选项里的 ...