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显示时间的控件 有默认宽高,不用设置数据源和代理 如何 ...
随机推荐
- maven认识
在这里普及一下知识: ┣ maven与ant是同类,构建工具 ┣ svn与cvs,css是同类,版本控制工具 1.为什么要用Maven? 在进行软件开发的过程中,无论什么项目,采用何种技术,使用何种编 ...
- loadrunner常用计数器分析
内存是第一个监视对象,确定系统瓶颈的第一个步骤就是排除内存问题.内存短缺的问题可能会引起各种各样的问题. Object(对象) Counters Description(描述) 参考值 Memory ...
- PAT1014
Suppose a bank has N windows open for service. 一个银行有N个服务的窗口 There is a yellow line in front of the w ...
- Html基础详解之(jquery)之二
on(events,[selector],[data],fn) 在选择元素上绑定一个或多个事件的事件处理函数.on()方法绑定时间处理程序到当前选定的jQuery对象中的元素.在jQuery 1.7中 ...
- Linux SCP命令复制传输文件的用法
SCP命令是用户通过网络将一台Linux服务器的文件复制到另一台Linux服务器,方法如下: 一:从本地复制到远程 复制文件: 命令格式: scp local_file remote_username ...
- 页面新宠图片格式WebP
WebP格式,谷歌(google)开发的一种旨在加快图片加载速度的图片格式.图片压缩体积大约只有JPEG的2/3,并能节省大量的服务器带宽资源和数据空间.Facebook Ebay等知名网站已经开始测 ...
- 使用JQuery结合HIghcharts实现从后台获取JSON实时刷新图表
项目做了一个报表,可以实时的观察呼叫中心的电话访问量,之前的版本是使用JFreechart做的,使用一段时间后出现内存溢出,服务器的内存使用量会变得很大,所以改用Ajax前台加载数据的方式实现实时报表 ...
- 配置suricata
yum -y install libpcap libpcap-devel libnet libnet-devel pcre \ pcre-devel gcc gcc-c++ automake auto ...
- JAVA的RSS处理
一:什么是RSS RSS(really simple syndication) :网页内容聚合器.RSS的格式是XML.必须符合XML 1.0规范. RSS的作用:订阅BLOG,订阅新闻二:RSS的历 ...
- 内联元素的特点SPAN
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...