IOS开发-UI学习-UITextField的具体属性及用法
直接上代码,里面有各种属性的用法注释,至于每个属性有多个可以设置的值,每个值的效果如何,可以通过查看这个函数参数的枚举量,并逐一测试。
//制作登陆界面
#import "ViewController.h" @interface ViewController (){ //定义全局变量(控件)
UITextField *username;
UITextField *password;
UIButton *resignbutton;
UIButton *loginbutton;
int i;
NSMutableArray *imagearray;
UIImageView *nameImage;
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; // 获取屏幕分辨率
CGRect rect = [[UIScreen mainScreen]bounds];
CGFloat screenw = rect.size.width;
CGFloat screenh = rect.size.height; // 初始化密码掩码标志位
i=; // 用户名输入框
// 创建
username = [[UITextField alloc]initWithFrame:CGRectMake(*screenw/, *screenh/, *screenw/, screenh/)];
// 设置边框
[username setBorderStyle:UITextBorderStyleRoundedRect];
// 设置水印提示
username.placeholder = @"请输入用户名:";
// 设置自动联想输入
username.autocorrectionType = UITextAutocorrectionTypeYes;
// 自动联想输入方式设置为根据单词首字母联想
username.autocapitalizationType = UITextAutocapitalizationTypeWords;
// 键盘右下角按键的类型
username.returnKeyType = UIReturnKeyDone;
// 右侧图片设置
// nameImage.image = [UIImage imageNamed:@"cat_eat0000.jpg"];
// 设置代理
username.delegate = self;
// 设置右侧清除按钮模式
username.clearButtonMode = UITextFieldViewModeWhileEditing;
// 初始化动画素材存放数组
imagearray = [[NSMutableArray alloc]initWithCapacity:];
// 通过循环为数组装载图片
for (int x=; x<; x++) {
[imagearray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"cat_eat00%.2d.jpg",x]]];
}
// 初始化图片位置,大小,由于图片限制在输入框右侧,所用坐标设置为0
nameImage = [[UIImageView alloc]initWithFrame:CGRectMake(, , , )];
// 设置输入框右侧动画图片来源为图片数组
nameImage.animationImages = imagearray;
// 设置动画播放持续时长
nameImage.animationDuration = ;
// 设置动画重复次数为无限循环
nameImage.animationRepeatCount = ; // 设置输入框右侧图片
username.rightView = nameImage;
// 设置右侧图片模式
password.rightViewMode = UITextFieldViewModeWhileEditing;
// 在启动程序后获取焦点
[username becomeFirstResponder];
// 加载到View上
[self.view addSubview:username]; // 密码输入框
password = [[UITextField alloc]initWithFrame:CGRectMake(*screenw/, *screenh/, *screenw/, screenh/)];
[password setBorderStyle:UITextBorderStyleRoundedRect];
// 设置输入提示水印文字
password.placeholder = [NSString stringWithFormat:@"请输入密码:"];
// 设置输入掩码
password.secureTextEntry = YES;
username.returnKeyType = UIReturnKeyDone;
// 设置字体和字号
password.font = [UIFont fontWithName:@"Arial" size:]; UIImageView *rightImage = [[UIImageView alloc]initWithFrame:CGRectMake(, , , )];
rightImage.image = [UIImage imageNamed:@""];
password.rightView = rightImage;
password.rightViewMode = UITextFieldViewModeWhileEditing;
[self.view addSubview:password]; // 设置密码输入框密码掩码开关的按钮
UIButton *eyebutton = [[UIButton alloc]initWithFrame:CGRectMake(*screenw/-*screenw/, *screenh/+, *screenw/, screenh/)];
eyebutton.backgroundColor = [UIColor whiteColor];
// eyebutton.alpha = 0;
eyebutton.alpha = 0.1; [eyebutton addTarget:self action:@selector(haha:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:eyebutton]; // 注册按钮
resignbutton = [[UIButton alloc]initWithFrame:CGRectMake(*screenw/, *screenh/, *screenw/, screenh/)];
[resignbutton setTitle:@"注册" forState:UIControlStateNormal];
resignbutton.backgroundColor = [UIColor colorWithRed:0.461 green:1.000 blue:0.856 alpha:1.000];
[self.view addSubview:resignbutton]; // 登陆按钮
loginbutton = [[UIButton alloc]initWithFrame:CGRectMake(*screenw/, *screenh/, *screenw/, screenh/)];
[loginbutton setTitle:@"登陆" forState:UIControlStateNormal];
loginbutton.backgroundColor = [UIColor colorWithRed:0.461 green:1.000 blue:0.856 alpha:1.000];
[self.view addSubview:loginbutton]; // 用户名提示
UILabel *usernamelabel =[[UILabel alloc]initWithFrame:CGRectMake(*screenw/, *screenh/, *screenw/, screenh/)];
usernamelabel.text = @"用户名:";
[self.view addSubview:usernamelabel]; // 密码输入提示
UILabel *passwordlabel =[[UILabel alloc]initWithFrame:CGRectMake(*screenw/, *screenh/, *screenw/, screenh/)];
passwordlabel.text = @"密码:";
[self.view addSubview:passwordlabel];
} //UiTextField代理事件
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
[nameImage startAnimating];
return YES;
} //设置密码输入框密码掩码开关的按钮响应事件
-(void)haha:(id)sender{
i++;
if (i%==) {
password.secureTextEntry = NO;
}if (i%==) {
password.secureTextEntry = YES;
} } //输入完后点击输入框空白处让键盘消失
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[username resignFirstResponder];
[password resignFirstResponder];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
具体效果如下:

IOS开发-UI学习-UITextField的具体属性及用法的更多相关文章
- iOS开发UI篇—CAlayer层的属性
iOS开发UI篇—CAlayer层的属性 一.position和anchorPoint 1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property ...
- ios开发UI篇—UITextfield
概述 UITextField在界面中显示可编辑文本区域的对象. 您可以使用文本字段来使用屏幕键盘从用户收集基于文本的输入.键盘可以配置许多不同类型的输入,如纯文本,电子邮件,数字等等.文本字段使用目标 ...
- iOS开发UI 篇—CAlayer层的属性
一.position和anchorPoint 1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property CGPoint position; 用来设 ...
- iOS开发UI篇—手写控件,frame,center和bounds属性
iOS开发UI基础—手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...
- iOS开发UI篇—transframe属性(形变)
iOS开发UI篇—transframe属性(形变) 1. transform属性 在OC中,通过transform属性可以修改对象的平移.缩放比例和旋转角度 常用的创建transform结构体方法分两 ...
- IOS开发UI篇—导航控制器属性和基本使用
IOS开发UI篇—导航控制器属性和基本使用 一.导航控制器的一些属性和基本使用 1.把子控制器添加到导航控制器中的四种方法 (1) 1.创建一个导航控制器 UINavigationController ...
- iOS开发UI篇—ios应用数据存储方式(XML属性列表-plist)
iOS开发UI篇—ios应用数据存储方式(XML属性列表-plist) 一.ios应用常用的数据存储方式 1.plist(XML属性列表归档) 2.偏好设置 3.NSKeydeArchiver归档(存 ...
- iOS开发UI基础—手写控件,frame,center和bounds属性
iOS开发UI基础—手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...
- iOS开发UI篇—transframe属性(形变)
iOS开发UI篇—transframe属性(形变) 1. transform属性 在OC中,通过transform属性可以修改对象的平移.缩放比例和旋转角度 常用的创建transform结构体方法分两 ...
- iOS开发UI篇—Date Picker和UITool Bar控件简单介绍
iOS开发UI篇—Date Picker和UITool Bar控件简单介绍 一.Date Picker控件 1.简单介绍: Date Picker显示时间的控件 有默认宽高,不用设置数据源和代理 如何 ...
随机推荐
- UVALive 2403 77377解题报告(深搜)
题意:给你一些固定的字符串,在给出数字,根据键盘的对应关系,输出所有的满足条件的字符串,输出顺序无所谓. 思路:因为题目说了,输出比较小,说明测试数据并不强,所以可以暴力回溯求出答案,将所有的给出的字 ...
- ARP/代理ARP
1.ARP首先讲到ARP,ARP是地址解析协议,它的作用是在以太网环境下,通过3层的IP地址来找寻2层的MAC地址,得到一张ARP缓存表.转发数据的时候根据ARP缓存表来进行传输.下图详细说明数据传输 ...
- hdu_5179_beautiful number(数位DP)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5179 题意:给你一个范围,问你漂亮的数有多少个,漂亮的数的定义为 数位高的比数位低的大,并且 数位高的 ...
- 这丫头也的还真清楚,但是跑不通呢,换3.0.3的mybatis也不行
http://java.dzone.com/articles/ibatis-mybatis-handling-joins http://mybatis.github.io/spring/mappers ...
- CentOS 6.2 安装vsftpd 服务器(转)
CentOS 6.2 安装vsftpd 服务器 本人的CentOS 6.2是安装在win 2008 R2 server 的 Hyper-V 虚拟机中.centos使用光盘安装,以最小模式安装,完成后用 ...
- python之路:进阶 二
c = collections.Counter( Counter({ b = collections.Counter( b.update(c) Counter({ Counter({ ...
- Task 编程中的异常处理
在 .Net 开发中, 使用 Task . Task<T> 进行异步编程是非常方便的, 但是在处理 Task 产生的异常时, 需要注意一个问题, 比如下面的代码: ? 1 2 3 4 5 ...
- phantom" breakpoints
http://stackoverflow.com/questions/723199/why-does-my-eclipse-project-have-phantom-debugger-breakpoi ...
- C#使用FFmpeg 将视频格式转换成MP4示例
一.常用视频格式分辨率 640x480p 720p格式,分辨率为1280×720p / 60Hz,行频为45kHz 1080p格式,分辨率为1920×1080逐行扫描,专业格式 二.FFmpeg部分参 ...
- latex题注(caption)位置
http://anything-is-ok.blog.163.com/blog/static/205720233201301634053760/ 我们以插入图片为例来说明latex中将题注(capti ...