LoginDemo
2015-11-20 17:28
190 查看
// // ViewController.m // FicowLoginDemo1 // // Created by Ficow on 15/11/12. // Copyright © 2015年 Ficow. All rights reserved. // #import "ViewController.h" @interface ViewController () @property (strong, nonatomic) IBOutlet UITextField *account; @property (strong, nonatomic) IBOutlet UITextField *password; @property (strong, nonatomic) IBOutlet UIButton *login; @property (strong, nonatomic) IBOutlet UIImageView *loginBackground; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //Notification监听代码 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidChange)//监听实现的方法 name:@"emptyInput" object:nil]; NSLog(@"Initiated"); } //实现点击背景隐藏键盘 - (IBAction)backgroundTap:(id)sender{ //将View的class设为UIControl NSLog(@"ViewTapped"); [[NSNotificationCenter defaultCenter] postNotificationName:@"emptyInput" object:self]; [self.account resignFirstResponder]; [self.password resignFirstResponder]; } //设置键盘的return key为next并跳转到下一个输入框,不要忘了设置return key属性 - (IBAction)nextInput:(id)sender{ NSLog(@"AccountInputFinished"); [[NSNotificationCenter defaultCenter] postNotificationName:@"emptyInput" object:self]; [self.account resignFirstResponder]; [self.password becomeFirstResponder]; } //输入结束,跳转到按钮,并点击按钮 - (IBAction)textFieldDoneEditing:(id)sender{ [[NSNotificationCenter defaultCenter] postNotificationName:@"emptyInput" object:self]; [sender resignFirstResponder]; // [self.login sendActionsForControlEvents:UIControlEventTouchUpInside]; NSLog(@"PasswordInputFinished"); } - (void)textFieldDidChange { NSLog(@"Notification is valid"); if (self.account.text.length == 0 || self.password.text.length == 0) { self.login.userInteractionEnabled = NO; self.login.alpha = 0.5; self.loginBackground.alpha = 0.2; } else{ self.login.userInteractionEnabled = YES; self.login.alpha = 1.0; self.loginBackground.alpha = 1.0; } } //错误警告弹出框 - (void) errorAlert:(id) sender :(NSString *) msg :(NSString *) title{ UIAlertController *controller = [UIAlertController alertControllerWithTitle:title/*警告框的标题*/ message:msg preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" /*警告框的确定键*/style:UIAlertActionStyleCancel handler:nil]; [controller addAction:cancelAction]; [self presentViewController:controller animated:YES completion:nil]; } - (IBAction)checkInput:(id)sender{//定义警告视图 NSString *msg = nil; NSString *title = nil; if([self.account.text isEqualToString:@"admin"] &&[self.password.text isEqualToString:@"1234"]){ msg = [NSString stringWithFormat:@"登录成功!"]; title = [NSString stringWithFormat:@"Welcome"]; }//demo1进行账号密码判空的部分 else{ if([self.password.text length] == 0 || [self.account.text length] == 0){ msg = [NSString stringWithFormat:@"账号/密码不能为空!"]; } else{ msg = [NSString stringWithFormat:@"账号/密码错误!"]; } title = [NSString stringWithFormat:@"Error"]; } [self errorAlert:sender :msg :title]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- YII重点文件
- C++拷贝构造函数(深拷贝,浅拷贝)
- Android打开MyEclipse报错:发现了以元素 'd:skin' 开头的无效内容。此处不应含有子元素。
- MySQL 学习笔记
- String、StringBuffer and StringBuilder
- F
- linux设备驱动归纳总结(二):模块的相关基础概念
- read 系统调用剖析
- 解决javax.persistence.TransactionRequiredException: Executing an update/delete query错误
- 自动删除源文件中的指定行--sed
- 保护程序猿滴眼睛---修改VS 2012 编辑器颜色
- 整洁代码
- 深入探讨this指针
- 存储过程
- AsyncTask使用
- 实现Comparator方式排序
- Spring+Mybatis多数据源配置(四)——AbstractRoutingDataSource实现数据源动态切换
- Spring+Mybatis多数据源配置(四)——AbstractRoutingDataSource实现数据源动态切换
- 广义表
- dos命令执行mysql的sql文件