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显示时间的控件 有默认宽高,不用设置数据源和代理 如何 ...
随机推荐
- 如何在Eclipse中添加Servlet-api.jar的方法
方法一: 点击窗口->首选项->java->构建路径->类路径变量->新建:将你的tomcat目录下的common/lib/servlet.jar加进来.如果你建立了一个 ...
- FZU 1914 Funny Positive Sequence(线性算法)
这个当时我没有做出来,看了很多人包括学长的代码才懂,我感觉最好的方法还是下面那一种,标记以谁开头的是不行的,我感觉有点不好理解,如果不懂举组样例在纸上写一下就会比较清楚了 #include<io ...
- Contest - 多校训练(985专场) Problem C: 985的方格难题
题目链接:http://acm.zzuli.edu.cn/zzuliacm/problem.php?cid=1157&pid=2 Description 985走入了一个n * n的方格地图, ...
- IndentationError: unexpected indent python
都知道python是对格式要求很严格的,写了一些python但是也没发现他严格在哪里,今天遇到了IndentationError: unexpected indent错误我才知道他是多么的严格. 以后 ...
- java监控函数执行时间
java监控函数执行时间 http://blog.csdn.net/ycg01/article/details/1467542 java监控函数执行时间 标签: javathreadclassstri ...
- HDU 1890 Robotic Sort | Splay
Robotic Sort Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) [Pr ...
- English--Computer System
A: Hey, Bill, Can you tell what's wrong with my computer? I can't move the mouse, I can's user the k ...
- app每个页面都有一个相同的浮层控件 实现思路
可以创建一个window,设置其windowLevel为alert;
- Linux操作系统入门教程
http://www.linuxidc.com/Linux/2015-07/120815p8.htm
- 修炼dp(1)
从最简单的开始: POJ:The Triangle #include <cstdio> #include <algorithm> #include <cstring> ...