iOS 注册或登录页面(UILable,UITextField,UIButton)
注册或登录页面
例如下面的附图
1,为了在这里展示UITextField文本框关联的键盘设置。在这里,“password”和“判定password”关联键盘被设置为数字键盘,实际应用password普遍认为,一个数字或字母。
2,了键盘收回操作。
3,这里没有写对“username”进行特殊字符过滤的代码。
实现代码:
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. //三个UILabel
UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 60, 80, 37)];
nameLabel.font = [UIFont systemFontOfSize:15];
nameLabel.text = @"用 户 名:";
nameLabel.backgroundColor = [UIColor clearColor];
nameLabel.textAlignment = NSTextAlignmentLeft;
nameLabel.numberOfLines = 2; //用于设置UILabel中文本的行数
[self.view addSubview:nameLabel];
[nameLabel release]; UILabel *newPasswordLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 60+40, 80, 37)];
newPasswordLabel.font = [UIFont systemFontOfSize:15];
newPasswordLabel.text = @"密 码:";
newPasswordLabel.backgroundColor = [UIColor clearColor];
newPasswordLabel.textAlignment = NSTextAlignmentLeft;
[self.view addSubview:newPasswordLabel];
[newPasswordLabel release]; UILabel *oncePasswordLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 60+40*2, 80, 37)];
oncePasswordLabel.font = [UIFont systemFontOfSize:15];
oncePasswordLabel.text = @"确认密码:";
oncePasswordLabel.backgroundColor = [UIColor clearColor];
oncePasswordLabel.textAlignment = NSTextAlignmentLeft;
[self.view addSubview:oncePasswordLabel];
[oncePasswordLabel release]; //三个输入框
UITextField *nameTextField = [[UITextField alloc]initWithFrame:CGRectMake(90, 60, 210, 30)];
nameTextField.placeholder = @"请输入username";
nameTextField.tag = 1;
[nameTextField setSecureTextEntry:NO];
nameTextField.font = [UIFont systemFontOfSize:14];
nameTextField.delegate = self;
nameTextField.backgroundColor = [UIColor clearColor];
nameTextField.borderStyle = UITextBorderStyleRoundedRect;
[self.view addSubview:nameTextField];
[nameTextField release]; UITextField *passwordTextField = [[UITextField alloc]initWithFrame:CGRectMake(90, 60+40, 210, 30)];
passwordTextField.placeholder = @"至少6位数字";
passwordTextField.tag = 2;
[passwordTextField setSecureTextEntry:YES];
passwordTextField.font = [UIFont systemFontOfSize:14];
passwordTextField.delegate = self;
passwordTextField.backgroundColor = [UIColor clearColor];
passwordTextField.borderStyle = UITextBorderStyleRoundedRect;
passwordTextField.keyboardType = UIKeyboardTypeNumberPad;
[self.view addSubview:passwordTextField];
[passwordTextField release]; UITextField *onceNewPasswordTextField = [[UITextField alloc]initWithFrame:CGRectMake(90, 60+40*2, 210, 30)];
onceNewPasswordTextField.placeholder = @"请再次输入密码";
onceNewPasswordTextField.tag = 3;
onceNewPasswordTextField.font = [UIFont systemFontOfSize:14];
[onceNewPasswordTextField setSecureTextEntry:YES];
onceNewPasswordTextField.delegate = self;
onceNewPasswordTextField.backgroundColor = [UIColor clearColor];
onceNewPasswordTextField.borderStyle = UITextBorderStyleRoundedRect;
onceNewPasswordTextField.keyboardType = UIKeyboardTypeNumberPad;
[self.view addSubview:onceNewPasswordTextField];
[onceNewPasswordTextField release]; UIButton *confirmButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
confirmButton.frame = CGRectMake(110, 60+40*3+20, 100, 37);
[confirmButton setTitle:@"确定" forState:UIControlStateNormal]; //正常状况下button显示的标题
[confirmButton setTitle:@"确定" forState:UIControlStateHighlighted]; //高亮显示时button的标题
confirmButton.backgroundColor = [UIColor redColor];
[confirmButton addTarget:self action:@selector(confirm:) forControlEvents:UIControlEventTouchUpInside];//button被按下又抬起后发生的事件
//@selector能够理解为"选择子",selector是一个指针变量,相似于sender。 这里是将method的方法指定给新建的这个confirmButton
[self.view addSubview:confirmButton];
} //收回键盘
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (int i = 0; i<4; i++) {
UITextField *textField = (UITextField*)[self.view viewWithTag:1+i];
[textField resignFirstResponder];
}
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
UILabel
UILabel继承了UIView,它能够设置UIView所支持的属性。
UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 20.0, 200.0, 50.0)]; //设置Label的位置和大小
//设置显示文字
label1.text = @"username";
//设置字体:粗体,正常的是 SystemFontOfSize
label1.font = [UIFont boldSystemFontOfSize:20];
//设置文字颜色
label1.textColor = [UIColor orangeColor];
//设置文字位置
label1.textAlignment = UITextAlignmentRight;
label2.textAlignment = UITextAlignmentCenter;
//设置字体大小适应label宽度
label4.adjustsFontSizeToFitWidth = YES;
//设置label的行数
label5.numberOfLines = 2;
UIlabel.backgroudColor=[UIColor clearColor]; //能够去掉背景色 //设置高亮
label6.highlighted = YES;
label6.highlightedTextColor = [UIColor orangeColor];
//设置阴影
label7.shadowColor = [UIColor redColor];
label7.shadowOffset = CGSizeMake(1.0,1.0);
//设置能否与用户进行交互
label7.userInteractionEnabled = YES;
//设置label中的文字是否可变,默认值是YES
label3.enabled = NO;
//设置文字过长时的显示格式
label3.lineBreakMode = UILineBreakModeMiddleTruncation;//截去中间
// typedef enum {
// UILineBreakModeWordWrap = 0,
// UILineBreakModeCharacterWrap,
// UILineBreakModeClip,//截去多余部分
// UILineBreakModeHeadTruncation,//截去头部
// UILineBreakModeTailTruncation,//截去尾部
// UILineBreakModeMiddleTruncation,//截去中间
// } UILineBreakMode; //假设adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为
label4.baselineAdjustment = UIBaselineAdjustmentNone;
// typedef enum {
// UIBaselineAdjustmentAlignBaselines,
// UIBaselineAdjustmentAlignCenters,
// UIBaselineAdjustmentNone,
// } UIBaselineAdjustment;
有时须要设置UILabel中文本的行数,其属性值默觉得1,用于设置该UILabel仅仅能显示一行文本。
oldPasswordLabel.numberOfLines = 2;
UITextField
//初始化textfield并设置位置及大小
UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, 30)]; //当输入框没有内容时。水印提示 ,提示内容为“username”
//显示灰色字体,作为提示信息
text.placeholder = @"username"; //设置边框样式,仅仅有设置了才会显示边框样式
text.borderStyle = UITextBorderStyleRoundedRect;
typedef enum {
UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect
} UITextBorderStyle; //设置键盘的样式
text.keyboardType = UIKeyboardTypeNumberPad;
typedef enum {
UIKeyboardTypeDefault, //默认键盘,支持全部字符
UIKeyboardTypeASCIICapable, //支持ASCII的默认键盘
UIKeyboardTypeNumbersAndPunctuation, //标准电话键盘,支持+*#字符
UIKeyboardTypeURL, //URL键盘,支持.combutton 仅仅支持URL字符
UIKeyboardTypeNumberPad, //数字键盘
UIKeyboardTypePhonePad, //电话键盘
UIKeyboardTypeNamePhonePad, //电话键盘,也支持输入人名
UIKeyboardTypeEmailAddress, //用于输入电子 邮件地址的键盘
UIKeyboardTypeDecimalPad, //数字键盘 有数字和小数点
UIKeyboardTypeTwitter, //优化的键盘。方便输入@、#字符
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable,
} UIKeyboardType; //每输入一个字符就变成点 用语password输入
text.secureTextEntry = YES; //设置输入框的背景颜色。此时设置为白色 假设使用了自己定义的背景图片边框会被忽略掉
text.backgroundColor = [UIColor whiteColor]; //设置背景图片
text.background = [UIImage imageNamed:@"dd.png"]; //设置背景
text.disabledBackground = [UIImage imageNamed:@"cc.png"]; //设置输入框内容的字体样式和大小
text.font = [UIFont fontWithName:@"Arial" size:20.0f]; //设置字体颜色
text.textColor = [UIColor redColor]; //输入框中是否有个叉号,在什么时候显示,用于一次性删除输入框中的内容
text.clearButtonMode = UITextFieldViewModeAlways;
typedef enum {
UITextFieldViewModeNever, //从不出现
UITextFieldViewModeWhileEditing, //编辑时出现
UITextFieldViewModeUnlessEditing, //除了编辑外都出现
UITextFieldViewModeAlways //一直出现
} UITextFieldViewMode; //输入框中一開始就有的文字
text.text = @"一開始就在输入框的文字"; //是否纠错
text.autocorrectionType = UITextAutocorrectionTypeNo;
typedef enum {
UITextAutocorrectionTypeDefault, //默认
UITextAutocorrectionTypeNo, //不自己主动纠错
UITextAutocorrectionTypeYes, //自己主动纠错
} UITextAutocorrectionType; //再次编辑就清空
text.clearsOnBeginEditing = YES; //内容对齐方式
text.textAlignment = UITextAlignmentLeft; //内容的垂直对齐方式 UITextField继承自UIControl,此类中有一个属性contentVerticalAlignment
text.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; //设置为YES时文本会自己主动缩小以适应文本窗体大小.默认是保持原来大小,而让长文本滚动
textFied.adjustsFontSizeToFitWidth = YES; //设置自己主动缩小显示的最小字体大小
text.minimumFontSize = 20; //首字母是否大写
text.autocapitalizationType = UITextAutocapitalizationTypeNone; typedef enum {
UITextAutocapitalizationTypeNone, 不自己主动大写
UITextAutocapitalizationTypeWords, 单词首字母大写
UITextAutocapitalizationTypeSentences, 句子的首字母大写
UITextAutocapitalizationTypeAllCharacters, 全部字母都大写
} UITextAutocapitalizationType; //return键变成什么键
text.returnKeyType =UIReturnKeyDone; typedef enum {
UIReturnKeyDefault, //默认 灰色button,标有Return
UIReturnKeyGo, //标有Go的蓝色button
UIReturnKeyGoogle, //标有Google的蓝色button,用语搜索
UIReturnKeyJoin, //标有Join的蓝色button
UIReturnKeyNext, //标有Next的蓝色button
UIReturnKeyRoute, //标有Route的蓝色button
UIReturnKeySearch, //标有Search的蓝色button
UIReturnKeySend, //标有Send的蓝色button
UIReturnKeyYahoo, //标有Yahoo的蓝色button
UIReturnKeyYahoo, //标有Yahoo的蓝色button
UIReturnKeyEmergencyCall, //紧急呼叫button
} UIReturnKeyType; //键盘外观
textView.keyboardAppearance=UIKeyboardAppearanceDefault;
typedef enum {
UIKeyboardAppearanceDefault。 //默认外观,浅灰色
UIKeyboardAppearanceAlert, //深灰 石墨色 } UIReturnKeyType; //设置代理 用于实现协议
text.delegate = self; //把textfield加到视图中
[self.window addSubview:text]; //最右側加图片是下面代码 左側相似
UIImageView *image=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right.png"]];
text.rightView=image;
text.rightViewMode = UITextFieldViewModeAlways;
typedef enum {
UITextFieldViewModeNever,
UITextFieldViewModeWhileEditing,
UITextFieldViewModeUnlessEditing,
UITextFieldViewModeAlways
} UITextFieldViewMode;
在处理password等隐私类的信息时,可能须要将输入的信息隐藏一下。
//每输入一个字符就变成点 ,用语密码输入
[passwordTextField setSecureTextEntry:YES];
也能够设置文本框关联的键盘。例如以下:
//设置键盘的样式
text.keyboardType = UIKeyboardTypeNumberPad;
typedef enum {
UIKeyboardTypeDefault, //默认键盘,支持全部字符
UIKeyboardTypeASCIICapable, //支持ASCII的默认键盘
UIKeyboardTypeNumbersAndPunctuation, //标准电话键盘。支持+*#字符
UIKeyboardTypeURL, //URL键盘,支持.combutton 仅仅支持URL字符
UIKeyboardTypeNumberPad, //数字键盘
UIKeyboardTypePhonePad, //电话键盘
UIKeyboardTypeNamePhonePad, //电话键盘。也支持输入人名
UIKeyboardTypeEmailAddress, //用于输入电子 邮件地址的键盘
UIKeyboardTypeDecimalPad, //数字键盘 有数字和小数点
UIKeyboardTypeTwitter, //优化的键盘,方便输入@、#字符
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable,
} UIKeyboardType;
有时须要限制输入文本的长度,这类操作也很普遍和重要。
//限制输入文本的长度
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if ([textField.text length] > MAXLENGTH)
{
textField.text = [textField.text substringToIndex:MAXLENGTH-1];
return NO;
}
return YES;
}
UIButton
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// 能够定义的button类型有以下6种,
// typedef enum {
// UIButtonTypeCustom = 0, 自己定义风格
// UIButtonTypeRoundedRect, 圆角矩形
// UIButtonTypeDetailDisclosure, 蓝色小箭头按钮,主要做具体说明用
// UIButtonTypeInfoLight, 亮色感叹号
// UIButtonTypeInfoDark, 暗色感叹号
// UIButtonTypeContactAdd, 十字加号按钮
// } UIButtonType; //给定button在view上的位置
button1.frame = CGRectMake(20, 20, 280, 20); //button背景色
button1.backgroundColor = [UIColor clearColor]; //设置button填充图片
//[button1 setImage:[UIImage imageNamed:@"btng.png"] forState:UIControlStateNormal]; //设置button标题
[button1 setTitle:@"点击" forState:UIControlStateNormal];
/* forState: 这个參数的作用是定义按钮的文字或图片在何种状态下才会显现*/
//以下是几种状态
// enum {
// UIControlStateNormal = 0, 常规状态显现
// UIControlStateHighlighted = 1 << 0, 高亮状态显现
// UIControlStateDisabled = 1 << 1, 禁用的状态才会显现
// UIControlStateSelected = 1 << 2, 选中状态
// UIControlStateApplication = 0x00FF0000, 当应用程序标志时
// UIControlStateReserved = 0xFF000000 为内部框架预留,能够无论他
// }; /*
* 默认情况下。当按钮高亮的情况下,图像的颜色会被画深一点。假设这以下的这个属性设置为no,
* 那么能够去掉这个功能
*/
button1.adjustsImageWhenHighlighted = NO;
/*跟上面的情况一样。默认情况下,当按钮禁用的时候,图像会被画得深一点,设置NO能够取消设置*/
button1.adjustsImageWhenDisabled = NO;
/* 以下的这个属性设置为yes的状态下,按钮按下会发光*/
button1.showsTouchWhenHighlighted = YES; /* 给button加入事件,事件有非常多种,我会单独开一篇博文介绍它们,以下这个时间的意思是
按下按钮,而且手指离开屏幕的时候触发这个事件,跟web中的click事件一样。
触发了这个事件以后,运行butClick:这种方法。addTarget:self 的意思是说。这种方法在本类中
也能够传入其它类的指针*/
[button1 addTarget:self action:@selector(butClick:) forControlEvents:UIControlEventTouchUpInside]; //显示控件
[self.view addSubview:button1];
单独说明一下:
UIButton *confirmButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
confirmButton.frame = CGRectMake(110, 60+40*3+20, 100, 37);
[confirmButton setTitle:@"确定" forState:UIControlStateNormal]; //正常状况下button显示的标题
[confirmButton setTitle:@"确定" forState:UIControlStateHighlighted]; //高亮显示时button的标题
confirmButton.backgroundColor = [UIColor redColor];
[confirmButton addTarget:self action:@selector(confirm:) forControlEvents:UIControlEventTouchUpInside];//button被按下又抬起后发生的事件
//@selector能够理解为"选择子",selector是一个指针变量,相似于sender。 这里是将method的方法指定给新建的这个confirmButton
[self.view addSubview:confirmButton];
若要设置UIButton的背景图片时:
UIButton *confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
confirmButton.frame = CGRectMake(10, 60, 100, 40);
UIImage *nextStepImage = [UIImage imageNamed:@"app.png"];
UIImage *nextStepDownImage = [UIImage imageNamed:@"app.png"];
nextStepImage = [nextStepImage resizableImageWithCapInsets:UIEdgeInsetsMake(8, 8, 8, 8)];
nextStepDownImage = [nextStepDownImage resizableImageWithCapInsets:UIEdgeInsetsMake(8, 8, 8, 8)];
[confirmButton setBackgroundImage:nextStepImage forState:UIControlStateNormal];
[confirmButton setBackgroundImage:nextStepDownImage forState:UIControlStateHighlighted];
[confirmButton setTitle:@"确定" forState:UIControlStateNormal];
[confirmButton addTarget:self action:@selector(confirm:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:confirmButton];
版权声明:本文博主原创文章。博客,未经同意不得转载。
iOS 注册或登录页面(UILable,UITextField,UIButton)的更多相关文章
- 1.注册或登录页面设计:UILabel,UIButton,UITextField
学习iOS开发已经有一段时日了,之前一直没有系统的对iOS开发的相关知识进行归纳总结,导致很多知识点云里雾里在脑子里形不成iOS开发的思想,现将自己在学习过程中遇到的一些知识进行总结,希望能对iOS初 ...
- UILable / UITextField / UIButton
// 获取屏幕大小的view UIView *contentView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; // ...
- 【web 回车】web项目 注册或登录页面 回车登录无效,解决方案
解决方案: /** * 登陆按钮的点击事件 */ $("#loginID").click(function(){ var username = $("#u"). ...
- bmob云 实现注册和登录的功能
向大家介绍一款我感觉非常溜的一款后端云服务bmob云 借助bmob云我们可以实现注册和登录页面的功能,下面就让我给大家演示一下借助bmob云服务实现这两个功能吧. 1. 用户是一个应用程序的核心.对 ...
- 再学ajax--第二天 | 基于php+mysql+ajax的表单注册、登录、注销
写在前面 ajax学习到了第二天,这次是用第一天封装的ajax函数,后端使用了php+mysql实现基本的注册,登录,注销. php是我前几个月get到的技能,我已经学习到了面向对象,知道各修饰符的含 ...
- 用Flutter开发的跨平台项目,完美运行在Android和IOS上,Material简洁风格,包括启动页、引导页、注册、登录、首页、体系、公众号、导航、项目,还有漂亮的妹子图库,运行极度流畅,结构清晰,代码规范,值得拥有
Flutter学习资源汇总持续更新中...... Flutter官方网站 Flutter中文网 wendux的Flutter实战 Flutter官方exampleflutter_gallery 阿里巴 ...
- 原生js验证简洁美观注册登录页面
序 一个以js验证表单的简洁的注册登录页面,不多说直接上图 效果 主要文件 完整代码 sign_up.html 注册表单 <!DOCTYPE html> <html lang=&qu ...
- PHP实现一个简陋的注册登录页面
PHP实现一个简陋的注册登录页面 今天来水一篇没有**用的 /滑稽脸,代码简陋臃肿考虑不全,各位大佬轻喷,还望不吝赐教. 首先考虑了一下需要至少四个页面:register.html.register. ...
- PHP——注册页面,审核页面,登录页面:加Session和Cookie
实现效果: 用户注册信息,管理员核对信息审核通过后,可实现注册的用户名和密码的成功登陆,利用session和cookie获取用户信息并且不能跳过登录页面直接进入主页面 1.Session存储在服务器可 ...
随机推荐
- BaaS简介
SaaS(软件即服务:Software as a Service).IaaS(基础设施即服务:Infrastructure as a Service)和PaaS(平台即服务:Platform as a ...
- 8.4 Android灯光系统_源码分析_电池灯
电池灯的Java代码在batteryservice.java中 电池的状态电量等信息由驱动获得,但驱动不会主动做这些事情,因此肯定有个App调用驱动程序读取电池信息,称这个App为A应用. 还有个Ap ...
- watchdog的正确使用方法
关于watchdog应该有过单片机学习经历的人.都比較熟悉.但watchdog的正确使用方法,恐怕大家假设没有经历过实际产品的开发不会有深入的理解. 瑞萨RL78系列的单片机自身带有watchdog, ...
- Android 利用an框架快速实现夜间模式的两种套路
作者:Bgwan链接:https://zhuanlan.zhihu.com/p/22520818来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 网上看到过大多实现夜间模 ...
- Java RMI使用
1. Java RMI介绍 RMI:远程方法调用(Remote Method Invocation).能够让在某个java虚拟机上的对象像调用本地对象方法一样调用另一个java 虚拟机中的对象上的方法 ...
- WCF走你~异常篇(永久更新...)
下面是我个人在进行WCF开发时,遇到的问题及相关的解决方法,供大家一起学习 1. ......HTTP 响应时发生错误.这可能是由于服务终结点绑定未使用 HTTP 协议造成的. 解决:把返回的实体类添 ...
- 使用Perl批量读取文件最后行
使用Perl批量读取文件最后行 面对成百上千个文件,有时我们需要查看它的最后行,单个文件打开将耗费大量时间,而通过Perl提取出最后行,将快速的帮助我们处理繁琐的事务. 特性 整个目录完全遍历,自动提 ...
- Linux系统编程——线程私有数据
在多线程程序中.常常要用全局变量来实现多个函数间的数据共享.因为数据空间是共享的,因此全局变量也为全部线程共同拥有. 測试代码例如以下: #include <stdio.h> #inclu ...
- [转载]Ocelot简易教程(一)Ocelot是什么
Ocelot简易教程(一)Ocelot是什么 简单的说Ocelot是一个用.NET Core实现并且开源的API网关技术. 可能你又要问了,什么是API网关技术呢?Ocelot又有什么特别呢?我们又该 ...
- 【34.14%】【BZOJ 3110】 [Zjoi2013]K大数查询
Time Limit: 20 Sec Memory Limit: 512 MB Submit: 5375 Solved: 1835 [Submit][Status][Discuss] Descript ...