//

//  AppDelegate.m

//  LessonaPackage

//

//  Created by lanouhn on 15/3/19.

//  Copyright (c) 2015年 lanouhn. All rights reserved.

//

 

#import "AppDelegate.h"

#import "LoginView.h"

 

#define kREGISTERVIEW 100

 

#define kLOGINVIEW 200

#define kLOGININUSERTEXTFIELD 201

#define kLOGINPASSWORDTEXTFIELD 202

 

#define kFINDVIEW 300

 

@interface AppDelegate () {

//    LoginView *loginView;

}

 

@end

 

@implementation AppDelegate

 

- (void)dealloc {

    [_window release];

    [super dealloc];

}

 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    

    //找回页面

    [self createFindView];

    

    //注册页面

    [self createRegisterView];

    

    //登录页面

    [self createLoginView];

    return YES;

}

//登录页面

- (void)createLoginView {

 

    UIView *loginView = [[UIView alloc] initWithFrame:_window.bounds];

    loginView.backgroundColor = [UIColor whiteColor];

    loginView.tag = kLOGINVIEW;

    [self.window addSubview:loginView];

    [loginView release];

    //用户label

    UILabel *userLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 40, 60, 30)];

    userLabel.text = @"用户名";

    [loginView addSubview:userLabel];

    [userLabel release];

    //密码label

    UILabel *passWorldLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 90, 60, 30)];

    passWorldLabel.text = @"密码";

    [loginView addSubview:passWorldLabel];

    [passWorldLabel release];

    //用户textFiedl

    UITextField *userNameTextFiedl = [[UITextField alloc] initWithFrame:CGRectMake(120, 40, 200, 30)];

    userNameTextFiedl.borderStyle = UITextBorderStyleRoundedRect;

    userNameTextFiedl.placeholder = @"请输入用户名";

    userNameTextFiedl.tag = kLOGININUSERTEXTFIELD;

    [loginView addSubview:userNameTextFiedl];

    [userNameTextFiedl release];

    //密码textFiedl

    UITextField *passWorldTextFiedl = [[UITextField alloc] initWithFrame:CGRectMake(120, 90, 200, 30)];

    passWorldTextFiedl.borderStyle = UITextBorderStyleRoundedRect;

    passWorldTextFiedl.placeholder = @"请输入密码";

    passWorldTextFiedl.tag = kLOGINPASSWORDTEXTFIELD;

    passWorldTextFiedl.secureTextEntry = YES;

    [loginView addSubview:passWorldTextFiedl];

    [passWorldTextFiedl release];

    //登录button

    UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeSystem];

    loginButton.frame = CGRectMake(60, 150, 60, 30);

    [loginButton setTitle:@"登录" forState:UIControlStateNormal];

    [loginButton addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];

//    [self login];

    [loginView addSubview:loginButton];

    //找回button

    UIButton *findButton = [UIButton buttonWithType:UIButtonTypeSystem];

    findButton.frame = CGRectMake(150, 150, 60, 30);

    [findButton setTitle:@"忘记密码" forState:UIControlStateNormal];

    [findButton addTarget:self action:@selector(pushToFindView) forControlEvents:UIControlEventTouchUpInside];

    [loginView addSubview:findButton];

    //注册button

    UIButton *registerButton = [UIButton buttonWithType:UIButtonTypeSystem];

    registerButton.frame = CGRectMake(240, 150, 60, 30);

    [registerButton setTitle:@"注册" forState:UIControlStateNormal];

    [registerButton addTarget:self action:@selector(pushToRegisterView) forControlEvents:UIControlEventTouchUpInside];

    [loginView addSubview:registerButton];

    

}

 

//找回密码页面

 

- (void)createFindView {

    //找回页面

    UIView *findView = [[UIView alloc] initWithFrame:_window.bounds];

    findView.backgroundColor = [UIColor whiteColor];

    findView.tag = kFINDVIEW;

    [self.window addSubview:findView];

    [findView release];

    //邮箱textFiedl

    UITextField *emailTextFiedl = [[UITextField alloc] initWithFrame:CGRectMake(60, 80, 250, 30)];

    emailTextFiedl.borderStyle = UITextBorderStyleRoundedRect;

    emailTextFiedl.placeholder = @"请输入邮箱";

    [findView addSubview:emailTextFiedl];

    [emailTextFiedl release];

    

    //找回button

    UIButton *findButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    findButton.frame = CGRectMake(60, 140, 60, 40);

    [findButton setTitle:@"找回" forState:UIControlStateNormal];

    [findView addSubview:findButton];

    

    //取消button

    UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    cancelButton.frame = CGRectMake(240, 140, 60, 40);

    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];

    [cancelButton addTarget:self action:@selector(pushToLoginView) forControlEvents:UIControlEventTouchUpInside];

    [findView addSubview:cancelButton];

}

 

//注册页面

- (void)createRegisterView {

    

    UIView *registerView = [[UIView alloc] initWithFrame:_window.bounds];

    registerView.backgroundColor = [UIColor whiteColor];

    registerView.tag = kREGISTERVIEW;

    [_window addSubview:registerView];

    [registerView release];

    

    //创建多个输入控件

    NSArray *nameArray = @[@"用户名", @"密码", @"确认密码", @"手机号", @"邮箱", @"住址"];

    for (NSInteger i = 0; i < 6; i++) {

        //label

        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 20 + 60 * i, 100, 40)];

        label.backgroundColor = [UIColor whiteColor];

        label.text = [NSString stringWithFormat:@"%@ :", nameArray[i]];

        label.textAlignment = NSTextAlignmentRight;

        [registerView addSubview:label];

        [label release];

        

        //textField

        UITextField *textFiedl = [[UITextField alloc] initWithFrame:CGRectMake(140, 20 + 60 * i, 200, 40)];

        textFiedl.borderStyle = UITextBorderStyleRoundedRect;

        textFiedl.placeholder = [NSString stringWithFormat:@"请输入%@", nameArray[i]];

        if (i == 2) {

            textFiedl.placeholder = @"请再次输入密码";

        }

        [registerView addSubview:textFiedl];

        [textFiedl release];

    }

    //注册button

    UIButton *registerButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    registerButton.frame = CGRectMake(60, 400, 60, 40);

    [registerButton setTitle:@"注册" forState:UIControlStateNormal];

    [registerView addSubview:registerButton];

    //取消button

    UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    cancelButton.frame = CGRectMake(250, 400, 60, 40);

    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];

    [cancelButton addTarget:self action:@selector(pushToLoginView) forControlEvents:UIControlEventTouchUpInside];

    [registerView addSubview:cancelButton];

}

 

//进入注册页面

- (void)pushToRegisterView {

    //找到注册页面

    UIView *registerView = [_window viewWithTag:kREGISTERVIEW];

    [_window bringSubviewToFront:registerView];

}

 

//进入找回密码页面

- (void)pushToFindView {

    UIView *findView = [_window viewWithTag:kFINDVIEW];

    [_window bringSubviewToFront:findView];

}

 

//返回登录页面

- (void)pushToLoginView {

    UIView *loginView = [_window viewWithTag:kLOGINVIEW];

    //登录页面提前

    [_window bringSubviewToFront:loginView];

}

 

//用户登录

- (void)login {

//    //登录页面

    UIView *loginView = [_window viewWithTag:kLOGINVIEW];

    //登录页面的textField

    UITextField *userTextFiedlT = (UITextField *)[loginView viewWithTag:kLOGININUSERTEXTFIELD];

    UITextField *passWorldTextFielT = (UITextField *)[loginView viewWithTag:kLOGINPASSWORDTEXTFIELD];

    

    if ([userTextFiedlT.text isEqualToString:@"591807572"] && [passWorldTextFielT.text isEqualToString:@"591807572"]) {

        UIAlertView *successAlertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"登录成功" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];

        [successAlertView show];

        [successAlertView release];

    } else if ([userTextFiedlT.text isEqualToString:@""] || [passWorldTextFielT.text isEqualToString:@""]) {

        UIAlertView *nilAlertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"用户名或密码不能为空" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];

        [nilAlertView show];

        [nilAlertView release];

    } else {

        UIAlertView *failAlertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"用户名或密码不正确" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];

        [failAlertView show];

        [failAlertView release];

    }

    

    

}

 

- (void)applicationWillResignActive:(UIApplication *)application {

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}

 

- (void)applicationDidEnterBackground:(UIApplication *)application {

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

 

- (void)applicationWillEnterForeground:(UIApplication *)application {

    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}

 

- (void)applicationDidBecomeActive:(UIApplication *)application {

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

 

- (void)applicationWillTerminate:(UIApplication *)application {

    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

 

@end

 

posted on 2015-03-19 21:10  小雪童鞋  阅读(209)  评论(0编辑  收藏  举报