zoukankan      html  css  js  c++  java
  • 登录注册页面的

    //第一页

    #import "ViewController.h"

    #import "LoginAndRegisterViewController.h"

    @interface ViewController ()

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        // 设置背景图

        [self setBackImageView];

        

        // 设置界面跳转的Button

        [self addButton];

    }

    - (void)setBackImageView

    {

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.frame];

        imageView.image = [UIImage imageNamed:@"2.jpg"];

        [self.view addSubview:imageView];

    }

    - (void)addButton

    {

        CGFloat btnH = 80;

        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 100, [UIScreen mainScreen].bounds.size.width, btnH)];

        [btn setTitle:@"进入APP" forState:UIControlStateNormal];

        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];

        btn.titleLabel.font = [UIFont systemFontOfSize:30];

        [btn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:btn];

    }

    - (void)clickBtn

    {

        // 模态形式切换界面

        

        // 1. 获取控制器对象

        LoginAndRegisterViewController *loginRVC = [[LoginAndRegisterViewController alloc] init];

        

        // 2. 设置动画的效果(可以省略)

    //    UIModalTransitionStyleCoverVertical = 0,

    //    UIModalTransitionStyleFlipHorizontal, // 翻转

    //    UIModalTransitionStyleCrossDissolve, // 渐变

    //    UIModalTransitionStylePartialCurl  // 书页

        // loginRVC.modalTransitionStyle = UIModalTransitionStylePartialCurl;

        

        // 3. 切换

        // 第一个参数:需要切换的控制器 第二个参数:切换过程中是否需要动画  第三个代码块:切换完成之后执行的操作

        [self presentViewController:loginRVC animated:YES completion:nil];

    }

     

    @end

     //2.登陆页

    #import "RegisterViewController.h"

    #import "SuccessViewController.h"

    #import "LoginAndRegisterViewController.h"

    @interface LoginAndRegisterViewController ()

    {

        UITextField *_userNameTF;

        UITextField *_userPasswordTF;

    }

    @end

    @implementation LoginAndRegisterViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        self.view.backgroundColor = [UIColor redColor];

        

        // 1. 添加背景图

        [self addBackGroundImageView];

        

        // 2. 用户名和密码框

        [self addNameAndPasswordTextField];

        

        // 3. 添加登录注册返回按钮

        [self addButtons];

    }

    - (void)addBackGroundImageView

    {

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.frame];

        imageView.image = [UIImage imageNamed:@"3.jpg"];

        [self.view addSubview:imageView];

    }

    - (void)addNameAndPasswordTextField

    {

        CGFloat textFieldX = 30;

        CGFloat textFieldY = 100;

        CGFloat textFieldW = self.view.frame.size.width - 2 * textFieldX;

        CGFloat textFieldH = 60;

        

        // 用户名输入框

        _userNameTF = [[UITextField alloc] initWithFrame:CGRectMake(textFieldX, textFieldY, textFieldW, textFieldH)];

        _userNameTF.backgroundColor = [UIColor whiteColor];

        _userNameTF.alpha = 0.6;

        _userNameTF.font = [UIFont systemFontOfSize:30];

        _userNameTF.clearButtonMode = UITextFieldViewModeWhileEditing;

        UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];

        leftImageView.image = [UIImage imageNamed:@"username"];

        _userNameTF.leftView = leftImageView;

        _userNameTF.leftViewMode = UITextFieldViewModeAlways;

        [self.view addSubview:_userNameTF];

        

        // 用户密码输入框

        _userPasswordTF = [[UITextField alloc] initWithFrame:CGRectMake(textFieldX, CGRectGetMaxY(_userNameTF.frame) + 30, textFieldW, textFieldH)];

        _userPasswordTF.backgroundColor = [UIColor whiteColor];

        _userPasswordTF.font = [UIFont systemFontOfSize:30];

        _userPasswordTF.alpha = 0.6;

        _userPasswordTF.clearButtonMode = UITextFieldViewModeWhileEditing;

        UIImageView *lImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];

        lImageView.image = [UIImage imageNamed:@"password"];

        _userPasswordTF.leftView = lImageView;

        _userPasswordTF.leftViewMode = UITextFieldViewModeAlways;

        _userPasswordTF.secureTextEntry = YES;

        [self.view addSubview:_userPasswordTF];

    }

    - (void)addButtons

    {

        CGFloat btnX = 0;

        CGFloat btnY = 0;

        CGFloat btnW = self.view.frame.size.width / 2;

        CGFloat btnH = 50;

        // 按钮的titile

        NSArray *array = @[@"登录",@"返回",@"注册"];

        for (int i = 0; i < 3; i ++) {

    #warning mark - 很诡异

            btnX = (i==1)?btnW:0;

            btnY = (i==2)?CGRectGetMaxY(_userPasswordTF.frame) + 30 + btnH:CGRectGetMaxY(_userPasswordTF.frame) + 30;

            

            UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(btnX, btnY, btnW, btnH)];

            [btn setTitle:array[i] forState:UIControlStateNormal];

            [btn setTitleColor:[UIColor yellowColor] forState:UIControlStateHighlighted];

            btn.tag = 100 + i;

            btn.titleLabel.font = [UIFont systemFontOfSize:30];

            [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];

            [self.view addSubview:btn];

        }

    }

    - (void)clickBtn:(UIButton *)sender

    {

        switch (sender.tag) {

            case 100:

                NSLog(@"登录");

                [self clickLoginBtn];

                break;

                

            case 101:

                NSLog(@"返回");

                [self dismissViewControllerAnimated:YES completion:nil];

                break;

                

            case 102:

            {

                NSLog(@"注册");

                RegisterViewController *registerVC = [[RegisterViewController alloc] init];

                [self presentViewController:registerVC animated:YES completion:nil];

            }

                

                break;

                

            default:

                break;

        }

    }

    - (void)clickLoginBtn

    {

        if ([_userNameTF.text  isEqualToString:@""] || [_userPasswordTF.text isEqualToString:@""] ) {

            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"用户名或密码不能为空" delegate:nil cancelButtonTitle:@"知道~~" otherButtonTitles:nil, nil];

            [alertView show];

        }else{

            NSString *userNameStr = _userNameTF.text;

            NSString *userPasswordStr = _userPasswordTF.text;

            

            // 单例(存储数据)

            NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

            NSDictionary *dict = [userDefaults objectForKey:@"GOUDAN"];

            

            NSString *passWord = [dict objectForKey:userNameStr];

            if ([passWord isEqualToString:userPasswordStr]) {// 登录成功

                SuccessViewController *successVC = [[SuccessViewController alloc] init];

                [self presentViewController:successVC animated:YES completion:nil];

            }

            

    //        // 返回

    //        [self dismissViewControllerAnimated:YES completion:nil];

        }

    }

    //3.注册页

    #import "RegisterViewController.h"

    @interface RegisterViewController ()

    {

        UITextField *_userNameTF;

        UITextField *_userPasswordTF;

    }

    @end

    @implementation RegisterViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        // 1. 添加背景图

        [self addBackGroundImageView];

        

        // 2. 用户名和密码框

        [self addNameAndPasswordTextField];

        

        // 3. 添加登录注册返回按钮

        [self addButtons];

        

    }

    - (void)addBackGroundImageView

    {

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.frame];

        imageView.image = [UIImage imageNamed:@"3.jpg"];

        [self.view addSubview:imageView];

    }

    - (void)addNameAndPasswordTextField

    {

        CGFloat textFieldX = 30;

        CGFloat textFieldY = 100;

        CGFloat textFieldW = self.view.frame.size.width - 2 * textFieldX;

        CGFloat textFieldH = 60;

        

        // 用户名输入框

        _userNameTF = [[UITextField alloc] initWithFrame:CGRectMake(textFieldX, textFieldY, textFieldW, textFieldH)];

        _userNameTF.backgroundColor = [UIColor whiteColor];

        _userNameTF.alpha = 0.6;

        _userNameTF.font = [UIFont systemFontOfSize:30];

        _userNameTF.clearButtonMode = UITextFieldViewModeWhileEditing;

        UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];

        leftImageView.image = [UIImage imageNamed:@"username"];

        _userNameTF.leftView = leftImageView;

        _userNameTF.leftViewMode = UITextFieldViewModeAlways;

        [self.view addSubview:_userNameTF];

        

        // 用户密码输入框

        _userPasswordTF = [[UITextField alloc] initWithFrame:CGRectMake(textFieldX, CGRectGetMaxY(_userNameTF.frame) + 30, textFieldW, textFieldH)];

        _userPasswordTF.backgroundColor = [UIColor whiteColor];

        _userPasswordTF.font = [UIFont systemFontOfSize:30];

        _userPasswordTF.alpha = 0.6;

        _userPasswordTF.clearButtonMode = UITextFieldViewModeWhileEditing;

        UIImageView *lImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];

        lImageView.image = [UIImage imageNamed:@"password"];

        _userPasswordTF.leftView = lImageView;

        _userPasswordTF.leftViewMode = UITextFieldViewModeAlways;

        _userPasswordTF.secureTextEntry = YES;

        [self.view addSubview:_userPasswordTF];

    }

    - (void)addButtons

    {

        CGFloat btnX = 0;

        CGFloat btnY = 0;

        CGFloat btnW = self.view.frame.size.width / 2;

        CGFloat btnH = 50;

        // 按钮的titile

        NSArray *array = @[@"注册",@"返回"];

        for (int i = 0; i < 2; i ++) {

            btnX = (i==1)?btnW:0;

            btnY = CGRectGetMaxY(_userPasswordTF.frame) + 30;

            UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(btnX, btnY, btnW, btnH)];

            [btn setTitle:array[i] forState:UIControlStateNormal];

            [btn setTitleColor:[UIColor yellowColor] forState:UIControlStateHighlighted];

            btn.tag = 100 + i;

            btn.titleLabel.font = [UIFont systemFontOfSize:30];

            [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];

            [self.view addSubview:btn];

        }

    }

    - (void)clickBtn:(UIButton *)sender

    {

        switch (sender.tag) {

            case 100:

                NSLog(@"注册");

                [self clickRegisterBtn];

                break;

                

            case 101:

                NSLog(@"返回");

                [self dismissViewControllerAnimated:YES completion:nil];

                break;

                

            default:

                break;

        }

    }

    - (void)clickRegisterBtn

    {

        // 1. 校验用户名和密码

        NSLog(@"----%@",_userNameTF.text);

        if ([_userNameTF.text  isEqualToString:@""] || [_userPasswordTF.text isEqualToString:@""] ) {

            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"用户名或密码不能为空" delegate:nil cancelButtonTitle:@"知道~~" otherButtonTitles:nil, nil];

            [alertView show];

        }else{

            NSString *userNameStr = _userNameTF.text;

            NSString *userPasswordStr = _userPasswordTF.text;

            

            // 单例(存储数据)

            NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

            NSDictionary *dict = @{userNameStr:userPasswordStr};

            [userDefaults setObject:dict forKey:@"GOUDAN"];

            

            // 返回

            [self dismissViewControllerAnimated:YES completion:nil];

        }

    }

    //4登陆成功页

    #import "SuccessViewController.h"

    @interface SuccessViewController ()

    @end

    @implementation SuccessViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.frame];

        imageView.image = [UIImage imageNamed:@"1.jpg"];

        [self.view addSubview:imageView];

    }

  • 相关阅读:
    HDOJ 5294 Tricks Device 最短路(记录路径)+最小割
    国家人工智能(AI)的美好前景
    预防埃博拉病毒感染的试验疫苗投入人体试验
    MySQL同步复制搭建方法指南详细步骤
    正则表达式,用相反的方式过滤掉特殊字符
    Linux入门教程
    Linux:-bash: ***: command not found
    linux命令大全
    linux下打开、关闭tomcat,实时查看tomcat运行日志
    chmod u+x ./j2sdk-1_4_2_04-linux-i586.bin的含义
  • 原文地址:https://www.cnblogs.com/fanwenzheIOS/p/4974268.html
Copyright © 2011-2022 走看看