//
// 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 == || self.password.text.length == ) {
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:@""]){
msg = [NSString stringWithFormat:@"登录成功!"];
title = [NSString stringWithFormat:@"Welcome"];
}//demo1进行账号密码判空的部分
else{
if([self.password.text length] == || [self.account.text length] == ){
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

可以学习一下使用ReactiveCocoa库来做LoginDemo,很好用哦!

iOS LoginDemo的更多相关文章

  1. IOS App如何调用python后端服务

    本篇文章旨在通过一个小的Demo形式来了解ios app是如何调用python后端服务的,以便我们在今后的工作中可以清晰的明白ios app与后端服务之间是如何实现交互的,今天的示例是拿登录功能做一个 ...

  2. iOS可视化动态绘制连通图

    上篇博客<iOS可视化动态绘制八种排序过程>可视化了一下一些排序的过程,本篇博客就来聊聊图的东西.在之前的博客中详细的讲过图的相关内容,比如<图的物理存储结构与深搜.广搜>.当 ...

  3. 【疯狂造轮子-iOS】JSON转Model系列之二

    [疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...

  4. 【疯狂造轮子-iOS】JSON转Model系列之一

    [疯狂造轮子-iOS]JSON转Model系列之一 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 之前一直看别人的源码,虽然对自己提升比较大,但毕竟不是自己写的,很容易遗 ...

  5. iOS总结_UI层自我复习总结

    UI层复习笔记 在main文件中,UIApplicationMain函数一共做了三件事 根据第三个参数创建了一个应用程序对象 默认写nil,即创建的是UIApplication类型的对象,此对象看成是 ...

  6. iOS代码规范(OC和Swift)

    下面说下iOS的代码规范问题,如果大家觉得还不错,可以直接用到项目中,有不同意见 可以在下面讨论下. 相信很多人工作中最烦的就是代码不规范,命名不规范,曾经见过一个VC里有3个按钮被命名为button ...

  7. JS调用Android、Ios原生控件

    在上一篇博客中已经和大家聊了,关于JS与Android.Ios原生控件之间相互通信的详细代码实现,今天我们一起聊一下JS调用Android.Ios通信的相同点和不同点,以便帮助我们在进行混合式开发时, ...

  8. 告别被拒,如何提升iOS审核通过率(上篇)

    iOS审核一直是每款移动产品上架苹果商店时面对的一座大山,每次提审都像是一次漫长而又悲壮的旅行,经常被苹果拒之门外,无比煎熬.那么问题来了,我们有没有什么办法准确把握苹果审核准则,从而提升审核的通过率 ...

  9. Swift3.0服务端开发(一) 完整示例概述及Perfect环境搭建与配置(服务端+iOS端)

    本篇博客算是一个开头,接下来会持续更新使用Swift3.0开发服务端相关的博客.当然,我们使用目前使用Swift开发服务端较为成熟的框架Perfect来实现.Perfect框架是加拿大一个创业团队开发 ...

随机推荐

  1. python基础——map/reduce

    python基础——map/reduce Python内建了map()和reduce()函数. 如果你读过Google的那篇大名鼎鼎的论文“MapReduce: Simplified Data Pro ...

  2. 1.2 容器-container

    1) *  容器是用于存放数据的类模板,实例化后就是容器类.用容器定义的对象称为容器对象. **类型相同的容器可以进行比较运算 2)分类 容器可分为顺序容器和关联容器两大类. *:顺序容器 元素的位置 ...

  3. php 复习

    <?php 一.php基础语法1.输出语句:echo print print_r var_dump() 2.php是弱类型语言强制转换类型: (类型)变量 settype(变量,类型) 3.变量 ...

  4. 数据结构和算法 – 12.高级查找算法(下)

    哈希(散列)技术既是一种存储方法,也是一种查找方法.然而它与线性表.树.图等结构不同的是,前面几种结构,数据元素之间都存在某种逻辑关系,可以用连线图示表示出来,而哈希技术的记录之间不存在什么逻辑关系, ...

  5. JavaWeb学习之转发和重定向、会话技术:cookie、session、验证码实例、URLConnection使用(下载网页)(4)

    1.转发和重定向 HttpServletResponse response 转发: RequestDispatcher dispatcher = request.getRequestDispatche ...

  6. sqlplus链接数据库报ORA-09925: Unable to create audit trail file

    [localhost.localdomain]:[/oracle11/app/oracle11/product/11.2.0/dbhome_1/dbs]$ sqlplus / as sysdba SQ ...

  7. 严重: End event threw exception java.lang.IllegalArgumentException: Can't convert argument: null

    堆栈信息: 2014-6-17 10:33:58 org.apache.tomcat.util.digester.Digester endElement 严重: End event threw exc ...

  8. Jquery easy UI 上中下三栏布局 分类: ASP.NET 2015-02-06 09:19 368人阅读 评论(0) 收藏

    效果图: 源代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...

  9. hdu 5033 单调栈 ****

    看出来是单调栈维护斜率,但是不会写,2333,原来是和询问放在一起的 #include <iostream> #include <cstdio> #include <cs ...

  10. web.xml中同一servlet/filter配置多个url-pattern

    转自:http://blog.sina.com.cn/s/blog_4c2c2a0c0100dh67.html 若你的servlet要多个地址,或你的filter需要过滤不同的url如有*.jsp,* ...