#import "AppDelegate.h"
//定义枚举值 -- 用来区分用户名好密码输入框
typedef enum : NSUInteger {
YHMNameTag = 101,
MMNameTag,
ZCYHMNameTag ,
ZCMMNameTag,
ZCQRMMNameTag,
ZCSJHNameTag,
ZCYXNameTag,
ZHMMYXNameTag,
} tagTag;
@interface AppDelegate ()<UITextFieldDelegate>
@property (nonatomic,strong)UIView *dengLu;
@property (nonatomic,strong)UIView *zhuCe;
@property (nonatomic,strong)UIView *zhaoHui;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//创建画板
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
//注册
self.zhuCe = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.zhuCe.backgroundColor = [UIColor whiteColor];
[self.window addSubview: self.zhuCe];
//找回
self.zhaoHui = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.zhaoHui.backgroundColor = [UIColor whiteColor];
[self.window addSubview:self.zhaoHui];
//登陆
self.dengLu = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.dengLu.backgroundColor = [UIColor whiteColor];
[self.window addSubview:self.dengLu];
//调用布局登陆页面的方法
[self setUpdengLuView];
//调用布局注册页面的方法
[self setUpZhuCeView];
//调用布局找回密码的方法
[self setUpZhaoHuiMiMaView];
return YES;
}
#pragma mark 登陆界面
//登陆界面
- (void)setUpdengLuView{
//用户名
UILabel *labelDL = [[UILabel alloc]initWithFrame:CGRectMake(50, 100, 80, 40)];
labelDL.backgroundColor = [UIColor whiteColor];
labelDL.text = @"用户名";
[self.dengLu addSubview:labelDL];
//用户名输入
UITextField *textFieldYHM = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(labelDL.frame) , CGRectGetMinY(labelDL.frame), 200, 40)];
textFieldYHM.placeholder = @"请输入用户名";
textFieldYHM.borderStyle = 3;//把输入框改为圆的
textFieldYHM.clearButtonMode = 1;//设置删除
textFieldYHM.returnKeyType = UIReturnKeyNext;//吧return换成nest
textFieldYHM.delegate = self;//代理
textFieldYHM.tag = YHMNameTag;//设置YHMNameTag的值
[self.dengLu addSubview:textFieldYHM];
//密码
UILabel *labelMM = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(labelDL.frame), CGRectGetMaxY(labelDL.frame) + 10, 80, 40)];
labelMM.backgroundColor = [UIColor whiteColor];
labelMM.text = @"密码";
[self.dengLu addSubview:labelMM];
//密码输入
UITextField *textFieldMM = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMinX(textFieldYHM.frame) , CGRectGetMaxY(textFieldYHM.frame) + 10, 200, 40)];
textFieldMM.placeholder = @"请输入密码";
textFieldMM.clearButtonMode = 1;
textFieldMM.secureTextEntry = 1;//安全密码
textFieldMM.borderStyle = 3;
textFieldMM.delegate = self;
textFieldMM.tag = MMNameTag;
[self.dengLu addSubview:textFieldMM];
//登录
UIButton *buttonDL = [UIButton buttonWithType:UIButtonTypeSystem];
buttonDL.frame = CGRectMake(CGRectGetMinX(labelMM.frame) , CGRectGetMaxY(labelMM.frame) + 20, 50, 50);
[buttonDL setTitle:@"登录" forState:UIControlStateNormal];
[buttonDL setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];//设置字体颜色
buttonDL.titleLabel.font = [UIFont systemFontOfSize:17.0];//设置字体
[self.dengLu addSubview:buttonDL];
[buttonDL addTarget:self action:@selector(DLDidClicked:) forControlEvents:UIControlEventTouchUpInside];//绑定
//找回密码
UIButton *buttonZHMM = [UIButton buttonWithType:UIButtonTypeSystem];
buttonZHMM.frame = CGRectMake(CGRectGetMaxX(buttonDL.frame), CGRectGetMinY(buttonDL.frame), 120, 50);
[buttonZHMM setTitle:@"找回密码" forState:UIControlStateNormal];
[buttonZHMM setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
buttonZHMM.titleLabel.font = [UIFont systemFontOfSize:17.0];
[self.dengLu addSubview:buttonZHMM];
[buttonZHMM addTarget:self action:@selector(ZHMMDidClicked:) forControlEvents:UIControlEventTouchUpInside];//绑定
//注册
UIButton *buttonZC = [UIButton buttonWithType:UIButtonTypeSystem];
buttonZC.frame = CGRectMake(CGRectGetMaxX(buttonZHMM.frame) + 20, CGRectGetMinY(buttonZHMM.frame), 50, 50);
[buttonZC setTitle:@"注册" forState:UIControlStateNormal];
[buttonZC setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
buttonZC.titleLabel.font = [UIFont systemFontOfSize:17.0];
[self.dengLu addSubview:buttonZC];
[buttonZC addTarget:self action:@selector(ZCDidClicked:) forControlEvents:UIControlEventTouchUpInside];//绑定
}
//次方法只要用来回收键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
UITextField *YHM = (UITextField *)[self.dengLu viewWithTag:YHMNameTag];
UITextField *MM = (UITextField *)[self.dengLu viewWithTag:MMNameTag];
UITextField *ZCYHM = (UITextField *)[self.zhuCe viewWithTag:ZCYHMNameTag];
UITextField *ZCMM = (UITextField *)[self.zhuCe viewWithTag:ZCMMNameTag];
UITextField *ZCQRMM = (UITextField *)[self.zhuCe viewWithTag:ZCQRMMNameTag];
UITextField *ZCSJH = (UITextField *)[self.zhuCe viewWithTag:ZCSJHNameTag];
UITextField *ZCYX = (UITextField *)[self.zhuCe viewWithTag:ZCYXNameTag];
// UITextField *ZHMMYX = (UITextField *)[self.zhaoHui viewWithTag:ZHMMYXNameTag];
if (textField.tag == YHMNameTag) {
//撤销用户名输入框的第一响应者
[YHM resignFirstResponder];
//让密码输入框变成第一响应者
[MM becomeFirstResponder];
}else{
//回收键盘
[textField resignFirstResponder];
}
// return YES;
if (textField.tag == ZCYHMNameTag) {
[ZCYHM resignFirstResponder ];
[ZCMM becomeFirstResponder];
} else if (textField.tag == ZCMMNameTag){
[ZCMM resignFirstResponder];
[ZCQRMM becomeFirstResponder];
} else if (textField.tag == ZCQRMMNameTag){
[ZCQRMM resignFirstResponder];
[ZCSJH becomeFirstResponder];
} else if (textField.tag == ZCSJHNameTag){
[ZCSJH resignFirstResponder];
[ZCYX becomeFirstResponder];
} else{
[textField resignFirstResponder];
}
return YES;
}
#pragma mark 注册界面
//注册界面
- (void)setUpZhuCeView{
//用户名
UILabel *labelZCYHM = [[UILabel alloc]initWithFrame:CGRectMake(50, 80, 80, 40)];
labelZCYHM.backgroundColor = [UIColor whiteColor];
labelZCYHM.text = @"用户名";
[self.zhuCe addSubview:labelZCYHM];
//请输入用户名
UITextField *textFieldZCSRYHM = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(labelZCYHM.frame) + 10, CGRectGetMinY(labelZCYHM.frame), 180, 40)];
textFieldZCSRYHM.placeholder = @"请输入用户名";
textFieldZCSRYHM.borderStyle = 3;
textFieldZCSRYHM.clearButtonMode = 1;
textFieldZCSRYHM.returnKeyType = UIReturnKeyNext;//把return换成nest
textFieldZCSRYHM.delegate = self;//设置代理
[self.zhuCe addSubview:textFieldZCSRYHM];
textFieldZCSRYHM.tag =ZCYHMNameTag;
//密码
UILabel *labelZCMM = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(labelZCYHM.frame), CGRectGetMaxY(labelZCYHM.frame) + 10, 80, 40)];
labelZCMM.text = @"密码";
labelZCMM.backgroundColor = [UIColor whiteColor];
[self.zhuCe addSubview:labelZCMM];
//请输入密码
UITextField *textFieldSRMM = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMinX(textFieldZCSRYHM.frame), CGRectGetMaxY(textFieldZCSRYHM.frame) + 10, 180, 40)];
textFieldSRMM.placeholder = @"请输入密码";
textFieldSRMM.clearButtonMode = 1;
textFieldSRMM.secureTextEntry = 1;//安全输入
textFieldSRMM.borderStyle = 3;//圆形输入框
[self.zhuCe addSubview:textFieldSRMM];
textFieldSRMM.delegate = self;
textFieldSRMM.returnKeyType = UIReturnKeyNext;
textFieldSRMM.tag = ZCMMNameTag;
//确认密码
UILabel *labelZCQRMM = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(labelZCMM.frame), CGRectGetMaxY(labelZCMM.frame) + 10, 80, 40)];
labelZCQRMM.text = @"确认密码";
labelZCQRMM.backgroundColor = [UIColor whiteColor];
[self.zhuCe addSubview:labelZCQRMM];
//再次输入密码
UITextField *textFieldZCQRMM = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMinX(textFieldSRMM.frame), CGRectGetMaxY(textFieldSRMM.frame) + 10, 180, 40)];
textFieldZCQRMM.placeholder = @"再次输入密码";
textFieldZCQRMM.clearButtonMode = 1;
textFieldZCQRMM.secureTextEntry = 1;
textFieldZCQRMM.borderStyle = 3;
[self.zhuCe addSubview:textFieldZCQRMM];
textFieldZCQRMM.delegate = self;
textFieldZCQRMM.returnKeyType = UIReturnKeyNext;
textFieldZCQRMM.tag = ZCQRMMNameTag;
//手机号
UILabel *labelZCSJH = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(labelZCQRMM.frame), CGRectGetMaxY(labelZCQRMM.frame) + 10, 80, 40)];
labelZCSJH.text = @"手机号";
labelZCSJH.backgroundColor = [UIColor whiteColor];
[self.zhuCe addSubview:labelZCSJH];
//请输入手机号
UITextField *textFieldSRSJH = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMinX(textFieldZCQRMM.frame), CGRectGetMaxY(textFieldZCQRMM.frame) + 10, 180, 40)];
textFieldSRSJH.placeholder = @"请输入手机号";
textFieldSRSJH.clearButtonMode = 1;
textFieldSRSJH.borderStyle = 3;
// textFieldSRSJH.keyboardType = UIKeyboardTypeNumberPad;
[self.zhuCe addSubview:textFieldSRSJH];
textFieldSRSJH.delegate = self;
textFieldSRSJH.returnKeyType = UIReturnKeyNext;
textFieldSRSJH.tag = ZCSJHNameTag;
//邮箱
UILabel *labelZCYX = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(labelZCSJH.frame), CGRectGetMaxY(labelZCSJH.frame) + 10, 80, 40)];
labelZCYX.text = @"邮箱";
labelZCYX.backgroundColor = [UIColor whiteColor];
[self.zhuCe addSubview:labelZCYX];
//请输入邮箱
UITextField *textFieldSRYX = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMinX(textFieldSRSJH.frame), CGRectGetMaxY(textFieldSRSJH.frame) + 10, 180, 40)];
textFieldSRYX.placeholder = @"请输入邮箱";
textFieldSRYX.clearButtonMode = 1;
textFieldSRYX.borderStyle = 3;
textFieldSRYX.keyboardType = 2;//邮箱的键盘
[self.zhuCe addSubview:textFieldSRYX];
textFieldSRYX.delegate = self;
textFieldSRYX.returnKeyType = UIReturnKeyNext;
textFieldSRYX.tag = ZCYXNameTag;
//注册
UIButton *buttonZCZC = [UIButton buttonWithType:UIButtonTypeSystem];
buttonZCZC.frame = CGRectMake(CGRectGetMinX(labelZCYX.frame) + 20, CGRectGetMaxY(labelZCYX.frame) + 10, 50, 50);
[buttonZCZC setTitle:@"注册" forState:UIControlStateNormal];
[self.zhuCe addSubview:buttonZCZC];
[buttonZCZC addTarget:self action:@selector(ZCZC:) forControlEvents:UIControlEventTouchUpInside];
//取消
UIButton *buttonZCQX = [UIButton buttonWithType:UIButtonTypeSystem];
buttonZCQX.frame = CGRectMake(CGRectGetMaxX(buttonZCZC.frame) + 100, CGRectGetMinY(buttonZCZC.frame), 50, 50);
[buttonZCQX setTitle:@"取消" forState:UIControlStateNormal];
[self.zhuCe addSubview:buttonZCQX];
[buttonZCQX addTarget:self action:@selector(QXFanhuizhujiemian:) forControlEvents:UIControlEventTouchUpInside];
}
#pragma mark 找回密码界面
- (void)setUpZhaoHuiMiMaView{
UITextField *textFieldDZYX = [[UITextField alloc]initWithFrame:CGRectMake(80, 120, 215, 50)];
textFieldDZYX.placeholder = @"电子邮箱";
textFieldDZYX.clearButtonMode = 1;
textFieldDZYX.borderStyle = 3;
textFieldDZYX.keyboardType = 2;
//textFieldDZYX.font = [UIFont systemFontOfSize:25.0];
[self.zhaoHui addSubview:textFieldDZYX];
textFieldDZYX.delegate = self;//代理。。回收键盘
textFieldDZYX.tag = ZHMMYXNameTag;
//找回
UIButton *buttonZH = [UIButton buttonWithType:UIButtonTypeSystem];
buttonZH.frame = CGRectMake(CGRectGetMinX(textFieldDZYX.frame), CGRectGetMaxY (textFieldDZYX.frame) + 20, 50, 50);
[buttonZH setTitle:@"找回" forState:UIControlStateNormal];
[self.zhaoHui addSubview:buttonZH];
[buttonZH addTarget:self action:@selector(zhaoHui:) forControlEvents:UIControlEventTouchUpInside];
//取消
UIButton *buttonQX = [UIButton buttonWithType:UIButtonTypeSystem];
buttonQX.frame = CGRectMake(CGRectGetMaxX(buttonZH.frame) + 100, CGRectGetMinY(buttonZH.frame), 50, 50);
[buttonQX setTitle:@"取消" forState:UIControlStateNormal];
[self.zhaoHui addSubview:buttonQX];
[buttonQX addTarget:self action:@selector(QXFanhuizhujiemian:) forControlEvents:UIControlEventTouchUpInside];//绑定
}
#pragma mark 布局登陆界面
- (void)DLDidClicked:(UIButton *)sender{
UITextField *YHM = (UITextField *)[self.dengLu viewWithTag:YHMNameTag];
UITextField *MM = (UITextField *)[self.dengLu viewWithTag:MMNameTag];
if ([YHM.text isEqual:@""] || [MM.text isEqual:@""] ) {
UIAlertView *filed = [[UIAlertView alloc] initWithTitle:@"提示" message:@"用户名或密码不能为空,请核对后重试" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[filed show];
} else if ([MM.text isEqual:@"321"] && [YHM.text isEqual:@"321"] ){
UIAlertView *filed = [[UIAlertView alloc] initWithTitle:@"提示" message:@"登录成功" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[filed show];
}
else{
UIAlertView *filed = [[UIAlertView alloc] initWithTitle:@"提示" message:@"用户名或密码不正确" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[filed show];
}
}
#pragma mark 登陆中的找回密码
- (void)zhaoHui:(UIButton *)sender{
UITextField *ZHMMYX = (UITextField *)[self.zhaoHui viewWithTag:ZHMMYXNameTag];
if ([ZHMMYX.text isEqualToString:@"[email protected]"]) {
UIAlertView *filed1 = [[UIAlertView alloc]initWithTitle:@"提示" message:@"找回成功 " delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[filed1 show];
} else{
UIAlertView *filed2 = [[UIAlertView alloc]initWithTitle:@"提示" message:@"找回失败。" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
[filed2 show];
}
}
#pragma mark 布局找回密码页面
- (void)ZHMMDidClicked:(UIButton *)sender{
self.dengLu.hidden = YES;
self.zhaoHui.hidden = NO;
}
#pragma mark 布局注册页面
- (void)ZCDidClicked:(UIButton *)sender{
self.dengLu.hidden = YES;
self.zhaoHui.hidden = YES;
self.zhuCe.hidden = NO;
}
#pragma mark 取消返回主界面
- (void)QXFanhuizhujiemian:(UIButton *)sender{
self.dengLu.hidden = NO;
self.zhaoHui.hidden = YES;
}
#pragma mark 注册中的注册情况
- (void)ZCZC:(UIButton *)sender{
UITextField *ZCYHM = (UITextField *)[self.zhuCe viewWithTag:ZCYHMNameTag];
UITextField *ZCMM = (UITextField *)[self.zhuCe viewWithTag:ZCMMNameTag];
UITextField *ZCQRMM = (UITextField *)[self.zhuCe viewWithTag:ZCQRMMNameTag];
UITextField *ZCSJH = (UITextField *)[self.zhuCe viewWithTag:ZCSJHNameTag];
UITextField *ZCYX = (UITextField *)[self.zhuCe viewWithTag:ZCYXNameTag];
if ([ZCYHM.text isEqual:@""] || [ZCMM.text isEqual:@""] || [ZCQRMM.text isEqual:@""]) {
UIAlertView *field = [[UIAlertView alloc]initWithTitle:@"提示" message:@"用户名或密码或确认密码 不能为空" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定 ", nil];
[field show];
} else if ([ZCMM.text isEqualToString:ZCQRMM.text] == 0){
UIAlertView *field = [[UIAlertView alloc]initWithTitle:@"提示" message:@"注密码不一致,请重新输入" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定 ", nil];
[field show];
} else if ([ZCSJH.text isEqual:@"153****23"] && [ZCYX.text isEqual:@"[email protected]"]){
UIAlertView *field = [[UIAlertView alloc]initWithTitle:@"提示" message:@"注册成功" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定 ", nil];
[field show];
} else{
UIAlertView *field = [[UIAlertView alloc]initWithTitle:@"提示" message:@"注册失败" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定 ", nil];
[field show];
}
}