textfield 登录页面Number&Password的同时判定
来源:互联网 发布:湘北vs陵南数据 编辑:程序博客网 时间:2024/05/02 01:58
//
// CONE.m
// TableView
//
// Created by 李小亮 on 16/6/8.
// Copyright © 2016年李小亮. All rights reserved.
//
#import "CONE.h"
@interface CONE ()
{
UITextField*number;
UITextField*password;
UIButton*button;
UILabel*label2;
UILabel*label3;
}
@end
@implementation CONE
- (void)viewDidLoad {
[superviewDidLoad];
self.title=@"首页";
//创建文本
UILabel*label=[[UILabelalloc]initWithFrame:CGRectMake(20, 250, 70, 40)];
label.text=@"账号:";
label.font=[UIFontsystemFontOfSize:25];
[self.viewaddSubview:label];
UILabel*label1=[[UILabelalloc]initWithFrame:CGRectMake(20, 330, 70, 40)];
label1.text=@"密码:";
label1.font=[UIFontsystemFontOfSize:25];
[self.viewaddSubview:label1];
//创建logo图片
UIImageView*imageView=[[UIImageViewalloc]init];
imageView.frame=CGRectMake(140, 100, 120, 120);
imageView.backgroundColor=[UIColorclearColor];
UIImage*image=[UIImageimageNamed:@"a.png"];
imageView.image=image;
imageView.layer.masksToBounds=YES;
imageView.layer.cornerRadius=60;
[self.viewaddSubview:imageView];
//创建帐号textfeild
number=[[UITextFieldalloc]initWithFrame:CGRectMake(85, 250, 250, 40)];
number.borderStyle=UITextBorderStyleRoundedRect;
number.backgroundColor=[UIColorgrayColor];
number.placeholder=@"请输入账号";
number.font=[UIFontfontWithName:@"正常"size:18.0f];
number.clearButtonMode=UITextFieldViewModeAlways;
number.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
number.delegate=self;//必须在.h中声明,在.h写上<UITextFieldDelegate>
[self.viewaddSubview:number];
//创建密码textfield
password=[[UITextFieldalloc]initWithFrame:CGRectMake(85, 330, 250, 40)];
password.borderStyle=UITextBorderStyleRoundedRect;
password.backgroundColor=[UIColorgrayColor];
password.placeholder=@"请输入密码";
password.font=[UIFontfontWithName:@"正常"size:18.0f];
password.clearButtonMode=UITextFieldViewModeAlways;
password.keyboardType=UIKeyboardTypeNumberPad;
password.delegate=self;//必须在.h中声明,在.h写上<UITextFieldDelegate>
[self.viewaddSubview:password];
//创建按钮
button=[UIButtonbuttonWithType:UIButtonTypeSystem];
button.frame=CGRectMake(20, 420, 320, 40);
button.backgroundColor=[UIColorgrayColor];
[buttonsetTitle:@"登录"forState:UIControlStateNormal];
[buttonsetTitleColor:[UIColorblackColor] forState:UIControlStateNormal];
button.layer.masksToBounds=YES;
button.layer.cornerRadius=6;
[buttonaddTarget:selfaction:@selector(ButtonClicked)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:button];
//监听键盘升起时的通知
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardwillshow)name:UIKeyboardWillShowNotificationobject:nil];
//监听键盘隐藏时的通知
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardwillhide)name:UIKeyboardWillHideNotificationobject:nil];
}
-(void)keyboardwillshow//键盘展示时,触发此事件
{
[UIViewanimateWithDuration:0.25animations:^{
button.frame=CGRectMake(20, 410, 320, 40);}completion:^(BOOL finished) {
}];
}
-(void)keyboardwillhide////键盘隐藏时,触发此事件
{
[UIViewanimateWithDuration:0.25animations:^{
button.frame=CGRectMake(20, 420 , 320, 40);}completion:^(BOOL finished) {
}];
}
//按钮点击事件
-(void)ButtonClicked{
if ([number.textisEqualToString:@"李亮"] &&[password.textisEqualToString:@"15991726153"]) {
NSLog(@"登录成功");
UIAlertView *alertView = [[UIAlertViewalloc] initWithTitle:@"提示"message:@"登录成功"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];
alertView.tag=1;
[alertView show];
}
else {
NSLog(@"登录失败");
UIAlertView *alertView1 = [[UIAlertViewalloc] initWithTitle:@"失败"message:@"消除文本框里的内容?"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];
alertView1.tag=2;
[alertView1 show];
}
NSLog(@"123");
}
#pragma mark ----提示框的代理方法
//根据被点击按钮的索引处理点击事件
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView.tag==1) {
NSLog(@"您点击的是成功的按钮");
if (buttonIndex==0) {
NSLog(@"您点击的是成功里的取消");
}else{
NSLog(@"您点击的是成功里的确认");
}
}elseif (alertView.tag==2){
NSLog(@"您点击的是失败的");
if (buttonIndex==0) {
NSLog(@"您点击的是失败里的取消");
}else{
NSLog(@"您点击的是失败里的确认");
number.text=nil;
password.text=nil;
}
}
}
#pragma mark ----textfield的代理方法
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
returnYES;
}
//进入编辑模式时调用
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
NSLog(@"进入编辑模式");
}
//textfield是否可以结束编辑
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
returnYES;//如果将return设置成NO,无法结束textfield的输入,点击其他textfield就无法输入内容
}
//结束编辑时调用
// -(void)textFieldDidEndEditing:(UITextField*)textField
// {
// NSLog(@"内容结束:%@",textField.text);
// if (textField.text.length!=11) {
// NSLog(@"您输入的内容太少了请重新输入");
// textField.text=nil;
// }
//
// }
//是否可以点击清除按钮
-(BOOL)textFiledShouldClear:(UITextField*)textfield
{
returnYES;
}
//点击空白处,收起键盘
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
[passwordresignFirstResponder];
[numberresignFirstResponder];
}
//是否可以点击return按钮
//-(BOOL)textFieldShouldReturn:(UITextField*)textField
//{
//点击return键盘收起
//[textField resignFirstResponder];
//return YES;
//}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
- textfield 登录页面Number&Password的同时判定
- smarty如何解决登录页面登录失败时在页面上同时显示失败的反馈信息的问题
- 简单的 对话框程序 Number Password
- Ext JS中隐藏TextField 同时隐藏 Label的方法
- 下拉框改变值,同时改变另一个TextField的FieldLabel
- textField和textView同时存在时的键盘监听
- (OK) links:命令行方式访问登录页面,输入 username & password
- 关于用户是否已经登录的判定
- 关于 “有道云笔记”,多个页面同时登录的问题
- 登录界面跳转,同时将onpause();方法中的保存的数据传到第二个页面
- textfield实现类似 Wechat 登录 按钮的状态
- Ext.data.Store加载时,给页面的textfield赋值
- 页面多个textField,键盘遮挡输入框的处理
- 在有Textfield的页面,键盘弹出效果
- 登录页面的样式
- 登录页面的验证
- 登录页面的背景图
- 史上最强的MSN同时登录
- vector 排序使用方式
- UITableViewCell去掉点击效果
- 第二十六章、MVP应用构架模式
- 纯CSS代码实现的图片列表滚动
- Spark技术文档---不错的博文
- textfield 登录页面Number&Password的同时判定
- 纯CSS实现鼠标移上图片添加阴影效果
- jenkins服务构建
- 与时议少年之苒苒
- WPF4.5 Introduction to the 24, "DataGrid Control Part 2"
- VS2015下如何使用Github的教程
- Js运动动画系列3--缓冲运动
- 设计模式一
- 大话Fragment管理