//
// 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. 60. Permutation Sequence

    题目: The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of t ...

  2. 关于s:iterator 和s:if 的结合使用

    <s:iterator value="list" status="st"> <div class="sidebar-nav" ...

  3. hdu 1257 最少拦截系统

    #include<time.h> #include <cstdio> #include <iostream> #include<algorithm> # ...

  4. UVA 10252

    按照字典序输出最长公共子序列 #include<time.h> #include <cstdio> #include <iostream> #include< ...

  5. Quartus 11.0 的AS 下载方式和JTAG下载jic文件的方式

    FPGA下载的三种方式:主动配置方式(AS)和被动配置方式(PS)和最常用的(JTAG)配置方式: AS由FPGA器件引导配置操作过程,它控制着外部存储器和初始化过程,EPCS系列.如EPCS1,EP ...

  6. 查看centos的版本

    [root@NB Desktop]# lsb_release -a LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4 ...

  7. 攻城狮在路上(壹) Hibernate(十六)--- Hibernate声明数据库事务

    一.数据库事务的概念: 数据库的ACID特征:Atomic.Consistency.Isolation.Durability.原子性.一致性.隔离性.持久性.不同的隔离级别引发的不同问题. 事务的AC ...

  8. 项目管理10000 hours – 瞎扯谈系列

    本系列会 zz 网上现有的文章,套句经典的话就是死磕自己,娱乐大众. 项目能否按时完成是项目管理的重要目标,将会面临的问题有团队的稳定性,冲突,会议以及压力. 团队中适度的人员流动是可以理解的,如何减 ...

  9. PHPCMS-V9 获取一级栏目、二级栏目、三级栏目

    <!-- 获取一级栏目 -->{pc:content action=" siteid="$siteid" order="listorder ASC& ...

  10. PMP 第五章 项目范围管理

    1.范围管理主要是干什么?什么是产品范围?什么是项目范围?    项目范围管理包括确保项目做而且只做成功完成项目所需的全部工作的各过程.管理项目范围主要是在定义和控制哪些工作应该包括在项目内,哪些不应 ...