简单的登陆页面练习


新建一个工程,实现登陆系统,即登陆页面、注册页面、找回密码页面之间的切换。

1、创建视图对象loginContainerView(登陆页面),registContainerView(注册页面),passwordContainerView(找回密码页面),将3个视图作为window的子视图。默认显示登陆页面。

2、点击登陆页面的登陆按钮,验证是否登陆成功。

3、点击登陆页面的找回密码按钮,切换显示找回密码页面。

4、点击登陆页面的注册按钮,切换显示注册页面。

5、点击找回密码页面的取消按钮,切换返回登陆页面。

6、点击注册页面的取消按钮,却换返回登陆页面。

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)dealloc {
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]]autorelease];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    //创建注册页面
    [self creatRegisterView];
    //创建找回密码页面
    [self creatFindPassView];
    //创建登陆页面
    [self creatLoginView];
    
    
    return YES;
}

- (void)creatLoginView {
    //登陆页面
    UIView *loginView = [[UIView alloc]initWithFrame:_window.frame];
    loginView.tag = 1000;
    loginView.backgroundColor = [UIColor whiteColor];
    [self.window addSubview:loginView];
    [loginView release];
    
    //用户名label
    UILabel *userNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 100, 80, 30)];
    userNameLabel.text = @"用户名";
    userNameLabel.backgroundColor = [UIColor whiteColor];
    [loginView addSubview:userNameLabel];
    [userNameLabel release];
    
    //密码label
    UILabel *passLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 150, 80, 30)];
    passLabel.text = @"密码";
    passLabel.backgroundColor = [UIColor whiteColor];
    [loginView addSubview:passLabel];
    [passLabel release];
    
    //用户名textField
    UITextField *userNameTF = [[UITextField alloc]initWithFrame:CGRectMake(130, 100, 200, 30)];
    userNameTF.tag = 1001;
    userNameTF.placeholder = @"请输入用户名";
    userNameTF.clearButtonMode = UITextFieldViewModeAlways;
    userNameTF.borderStyle = UITextBorderStyleRoundedRect;
    [loginView addSubview:userNameTF];
    userNameTF.keyboardType = UIKeyboardTypeDefault;//键盘类型
    userNameTF.returnKeyType = UIReturnKeyDone;
    
    //设置代理
    userNameTF.delegate = self;
    [userNameTF release];
    
    //密码textField
    UITextField *passTF = [[UITextField alloc]initWithFrame:CGRectMake(130, 150, 200, 30)];
    passTF.tag = 1002;
    passTF.placeholder = @"请输入密码";
    passTF.secureTextEntry = YES;
    passTF.clearButtonMode = UITextFieldViewModeAlways;
    passTF.borderStyle = UITextBorderStyleRoundedRect;
    [loginView addSubview:passTF];
    
    passTF.delegate = self;//代理
    [passTF release];
    
    //登陆button
    UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeSystem];
    loginButton.frame = CGRectMake(40, 200, 80, 30);
    loginButton.backgroundColor = [UIColor whiteColor];
    loginButton.titleLabel.font = [UIFont systemFontOfSize:18];//字号
    loginButton.backgroundColor = [UIColor whiteColor];
    [loginButton setTitle:@"登陆" forState:UIControlStateNormal];
//    [loginButton addTarget:self action:@selector(pushLoginView) forControlEvents:UIControlEventTouchUpInside];
    [loginButton addTarget:self action:@selector(pushLogin) forControlEvents:UIControlEventTouchUpInside];
    [loginView addSubview:loginButton];
    
    //注册button
    UIButton *registerButton = [UIButton buttonWithType:UIButtonTypeSystem];
    registerButton.frame = CGRectMake(150, 200, 80, 30);
    registerButton.titleLabel.font = [UIFont systemFontOfSize:18];
    registerButton.backgroundColor = [UIColor whiteColor];
    [registerButton setTitle:@"注册" forState:UIControlStateNormal];
    [registerButton addTarget:self action:@selector(pushRegister) forControlEvents:UIControlEventTouchUpInside];
    [loginView addSubview:registerButton];
    
    //找回密码button
    UIButton *findPassButton = [UIButton buttonWithType:UIButtonTypeSystem];
    findPassButton.frame = CGRectMake(260, 200, 80, 30);
    findPassButton.titleLabel.font = [UIFont systemFontOfSize:18];
    findPassButton.backgroundColor = [UIColor whiteColor];
    [findPassButton setTitle:@"找回密码" forState:UIControlStateNormal];
    [findPassButton addTarget:self action:@selector(pushFindPass) forControlEvents:UIControlEventTouchUpInside];
    [loginView addSubview:findPassButton];
}

- (void)pushLoginView {
    //找到登陆界面
    UIView *loginView = [_window viewWithTag:1000];
    //登陆页面提前
    [_window bringSubviewToFront:loginView];
}

- (void)pushRegister {
    UIView *registerView = [_window viewWithTag:1003];
    [_window bringSubviewToFront: registerView];
}

- (void)pushFindPass {
    UIView *findPassView = [_window viewWithTag:1004];
    [_window bringSubviewToFront:findPassView];
}

- (void)pushLogin {
    //登陆界面
    UIView *loginView = [_window viewWithTag:1000];
    //登陆页面上用户名输入框
    UITextField *userTextField = (UITextField *)[loginView viewWithTag:1001];
    //登陆页面上的密码输入框
    UITextField *passTextField = (UITextField *)[loginView viewWithTag:1002];
    
    if (userTextField.text.length == 0) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"用户名不能为空" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alertView show];
        [alertView release];
    }else if (passTextField.text.length == 0) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示"message:@"密码不能为空" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alertView show];
        [alertView release];
    }else if ([userTextField.text isEqualToString:@"lanou"] == 1 && [passTextField.text isEqualToString:@"12345"] == 1) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"登陆成功" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alertView show];
        [alertView release];
    }else {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"用户名或者密码错误,请核对后再试" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alertView show];
        [alertView release];
    }
}

- (void)creatRegisterView {
    //注册界面
    UIView *registerView = [[UIView alloc]initWithFrame:self.window.frame];
    registerView.tag = 1003;
    registerView.backgroundColor = [UIColor whiteColor];
    [self.window addSubview:registerView];
    [registerView release];
    
    //label的创建
    NSArray *array = @[@"用户名",@"密码",@"确定密码",@"电话",@"邮箱",@"地址"];
    for (NSInteger i = 0;i < 6;i++) {
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(40, 80+60*i, 90, 40)];
        label.text = [NSString stringWithFormat:@"%@:",array[i]];
        label.textAlignment = NSTextAlignmentRight;
        label.font = [UIFont systemFontOfSize:20];
        label.backgroundColor = [UIColor whiteColor];
        [registerView addSubview:label];
        [label release];
        
     //textField的创建
        UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(160, 80 +60*i, 160, 40)];
        textField.font = [UIFont systemFontOfSize:20];
        textField.placeholder = [NSString stringWithFormat:@"请输入%@",array[i]];
        if (i == 2) {
            textField.placeholder = @"请再次输入密码";
        }
        textField.backgroundColor = [UIColor whiteColor];
        textField.borderStyle = UITextBorderStyleRoundedRect;
        [registerView addSubview:textField];
        
        textField.delegate = self;//代理
        [textField release];
    }
    
    //注册button
    UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeSystem];
    loginButton.frame = CGRectMake(70, 500, 100, 30);
    loginButton.backgroundColor = [UIColor whiteColor];
    loginButton.titleLabel.font = [UIFont systemFontOfSize:18];
    [loginButton setTitle:@"注册" forState:UIControlStateNormal];
    [registerView addSubview:loginButton];
    
    //取消button
    UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeSystem];
    cancelButton.frame = CGRectMake(200, 500, 100, 30);
    cancelButton.backgroundColor = [UIColor whiteColor];
    cancelButton.titleLabel.font = [UIFont systemFontOfSize:18];
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [cancelButton addTarget:self action:@selector(pushLoginView) forControlEvents:UIControlEventTouchUpInside];//跳转页面
    [registerView addSubview:cancelButton];
    
}
- (void)creatFindPassView {
    //找回密码界面
    UIView *findPassView = [[UIView alloc]initWithFrame:_window.frame];
    findPassView.tag = 1004;
    findPassView.backgroundColor = [UIColor whiteColor];
    [_window addSubview:findPassView];
    [findPassView release];
    
    //邮箱textfield
    UITextField *mailTextField = [[UITextField alloc]initWithFrame:CGRectMake(80, 80, 250, 40)];
    mailTextField.backgroundColor = [UIColor whiteColor];
    mailTextField.font = [UIFont systemFontOfSize:20];
    mailTextField.placeholder = @"请输入电子邮箱";
    mailTextField.borderStyle = UITextBorderStyleRoundedRect;
    [findPassView addSubview:mailTextField];
    
    mailTextField.delegate = self;//代理
    [mailTextField release];
    
    //返回Button
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeSystem];
    backButton.frame = CGRectMake(80, 150, 100, 40);
    backButton.backgroundColor = [UIColor whiteColor];
    backButton.titleLabel.font = [UIFont systemFontOfSize:18];
    [backButton setTitle:@"找回" forState:UIControlStateNormal];
    [findPassView addSubview:backButton];
    
    //取消button
    UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeSystem];
    cancelButton.frame = CGRectMake(220, 150, 100, 40);
    cancelButton.backgroundColor = [UIColor whiteColor];
    cancelButton.titleLabel.font = [UIFont systemFontOfSize:18];
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    
    [cancelButton addTarget:self action:@selector(pushLoginView) forControlEvents:UIControlEventTouchUpInside];//跳转页面
    [findPassView addSubview:cancelButton];
    
}

//收回键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (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
				
时间: 2024-08-08 21:53:05

简单的登陆页面练习的相关文章

html+js实现简单的登陆页面

初学web自动化,学习简单的前端知识还是很有必要的: 今天我们利用html实现一个简单的登陆页面,并利用js提取用户名和密码,在alert弹窗中显示出来 实现的功能: 1.实现重置按钮的功能,点击重置按钮,能清除你填写的数据 2.填写用户名,密码,点击登录,获取到用户名和密码通过alert提示框展示出来. 页面如图: 代码如下: <!DOCTYPE html><html> <head> <title>登陆.html</title> </he

Android笔记-4-实现登陆页面并跳转和简单的注册页面

实现登陆页面并跳转和简单的注册页面 首先我们来看看布局的xml代码 login.xml <span style="font-family:Arial;font-size:18px;"><?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu

Android简单登陆页面

布局: 线性布局+相对布局 日志打印: 利用LogCat和System.out.println打印观察. Onclick事件是采用过的第四种: 在配置文件中给Button添加点击时间 涉及知识: 通过上线文context获得文件的路径和缓存路径,保存文件 布局代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.an

python编写简单的html登陆页面(3)

1  在python编写简单的html登陆页面(2)的基础上在延伸一下: 可以将静态分配数据,建立表格,存放学生信息 2  加载到静态数据 3  html的编写直接在表格里添加一组数据就行了 4  VS Code上面跟前面的后台类似,添加一个content再链接到html就可以了 @app.route('/content')def content(): return render_template('content.html') return 'content.....'

python编写简单的html登陆页面(2)

1  在python编写简单的html登陆页面(1)的基础上在延伸一下: 可以将动态分配数据,实现页面跳转功能: 2  跳转到新的页面:return render_template('home1.html') 3  后台代码如下 4  前端html:

小KING教你做android项目(二)---实现登陆页面并跳转和简单的注册页面

原文:http://blog.csdn.net/jkingcl/article/details/10989773 今天我们主要来介绍登陆页面的实现,主要讲解的就是涉及到的布局,以及简单的跳转需要用到的代码. 首先我们来看看布局的xml代码 login.xml [html] view plaincopy <span style="font-family:Arial;font-size:18px;"><?xml version="1.0" encodi

一个简单的登陆注册的页面

首先声明,这行代码不用于开发. 1.login.html <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>登陆页面</title> </head> <style> .box{ height: 30px; width: 300px; position: absolute; top:5

python编写简单的html登陆页面(1)

1  html 打开调式效果如下 2  用python后台编写 # coding:utf-8# 从同一个位置导入多个工具,# 这些工具之间可以用逗号隔开,同时导入# render_template渲染母版from flask import Flask,render_template app=Flask(__name__)# 装饰器,路由用来封装链接,同时返回数据@app.route('/index')def index_xxx(): # 导入html # 需要在桌面建立一个templates文件

用struts2做简单的登陆

利用strust2做一个简单的登陆界面,能对登陆的用户名进行检查. 把登陆的用户名和密码做一个到javabean中,就是将其封装. User类省略 LoginAction struts.xml配置 login登陆界面 成功 和 错误界面省略 在这个例子中我犯了这样的错误 因为username 和password被封装了,我的登陆界面开始 的提交是这样写的 <input name=“username”.................> 这样一直是在空指针异常 我当时通过先取消比对用户这段代码,