iOS LoginDemo
//
// 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的更多相关文章
- IOS App如何调用python后端服务
本篇文章旨在通过一个小的Demo形式来了解ios app是如何调用python后端服务的,以便我们在今后的工作中可以清晰的明白ios app与后端服务之间是如何实现交互的,今天的示例是拿登录功能做一个 ...
- iOS可视化动态绘制连通图
上篇博客<iOS可视化动态绘制八种排序过程>可视化了一下一些排序的过程,本篇博客就来聊聊图的东西.在之前的博客中详细的讲过图的相关内容,比如<图的物理存储结构与深搜.广搜>.当 ...
- 【疯狂造轮子-iOS】JSON转Model系列之二
[疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...
- 【疯狂造轮子-iOS】JSON转Model系列之一
[疯狂造轮子-iOS]JSON转Model系列之一 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 之前一直看别人的源码,虽然对自己提升比较大,但毕竟不是自己写的,很容易遗 ...
- iOS总结_UI层自我复习总结
UI层复习笔记 在main文件中,UIApplicationMain函数一共做了三件事 根据第三个参数创建了一个应用程序对象 默认写nil,即创建的是UIApplication类型的对象,此对象看成是 ...
- iOS代码规范(OC和Swift)
下面说下iOS的代码规范问题,如果大家觉得还不错,可以直接用到项目中,有不同意见 可以在下面讨论下. 相信很多人工作中最烦的就是代码不规范,命名不规范,曾经见过一个VC里有3个按钮被命名为button ...
- JS调用Android、Ios原生控件
在上一篇博客中已经和大家聊了,关于JS与Android.Ios原生控件之间相互通信的详细代码实现,今天我们一起聊一下JS调用Android.Ios通信的相同点和不同点,以便帮助我们在进行混合式开发时, ...
- 告别被拒,如何提升iOS审核通过率(上篇)
iOS审核一直是每款移动产品上架苹果商店时面对的一座大山,每次提审都像是一次漫长而又悲壮的旅行,经常被苹果拒之门外,无比煎熬.那么问题来了,我们有没有什么办法准确把握苹果审核准则,从而提升审核的通过率 ...
- Swift3.0服务端开发(一) 完整示例概述及Perfect环境搭建与配置(服务端+iOS端)
本篇博客算是一个开头,接下来会持续更新使用Swift3.0开发服务端相关的博客.当然,我们使用目前使用Swift开发服务端较为成熟的框架Perfect来实现.Perfect框架是加拿大一个创业团队开发 ...
随机推荐
- 多线程编程4 - NSOperationQueue
一.简介 一个NSOperation对象可以通过调用start方法来执行任务,默认是同步执行的.也可以将NSOperation添加到一个NSOperationQueue(操作队列)中去执行,而且是异步 ...
- Linux mpstat字段解析
mpstat是Multiprocessor Statistics的缩写,是实时系统监控工具.其报告与CPU的一些统计信息,这些信息存放在/proc/stat文件中.在多CPUs系统里,其不但能查看所有 ...
- UbuntuLinux安装java
jdk1.7,jdk1.8详情,参见:http://www.cnblogs.com/a2211009/p/4265225.html
- nyoj998(euler)
题意:题意:给出n和m,求满足条件gcd(x, n)>=m的x的gcd(x, n)的和,其中1<=x<=n,1<= n, m <= 1e9:思路:此题和nyoj1007差 ...
- 《Thinking in Java》十四章类型信息_习题解
1~10 Page 318 练习1. 在ToyTest.java中,将Toy的默认构造器注释掉,并解释发生的现象. 书中代码如下(略有改动): package org.cc.foo_008; p ...
- 启动ip转法功能
这种方法无需重启: [root@ha02 ~]# cat /proc/sys/net/ipv4/ip_forward [root@ha02 ~]# sysctl -w net.ipv4.ip_forw ...
- c# 扩展方法奇思妙用基础篇八:Distinct 扩展(转载)
转载地址:http://www.cnblogs.com/ldp615/archive/2011/08/01/distinct-entension.html 刚看了篇文章 <Linq的Distin ...
- Delphi线程的终止
当线程对象的Execute()执行完毕,我们就认为此线程终止了.这时候,它会调用Delphi的一个标准例程EndThread(),这个例程再调用API函数ExitThread().由ExitThrea ...
- 【翻译十八】java-并发之锁对象
Lock Objects Synchronized code relies on a simple kind of reentrant lock. This kind of lock is easy ...
- 《图形学》实验四:中点Bresenham算法画直线
开发环境: VC++6.0,OpenGL 实验内容: 使用中点Bresenham算法画直线. 实验结果: 代码: //中点Bresenham算法生成直线 #include <gl/glut.h& ...