iOS UI03_登陸+註冊 UI1~3系統歸納

完成登陸系統(登陸、註冊、找回密碼),使用容器視圖控制器實現。
定義容器視圖控制器ContainerViewController,指定爲window的根視圖控制器。
定義LoginViewController、RegistViewController、PasswordViewController,三個視圖控制器的根視圖添加到容器視圖控制器的根視圖。
//
//  AppDelegate.m
//  UI作業03
//
//  Created by dllo on 15/7/31.
//  Copyright (c) 2015年 zhozhicheng. All rights reserved.
//

#import "AppDelegate.h"
#import "LoginViewController.h"
#import "RegistViewController.h"
#import "PasswordViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate
-(void)dealloc
{
    [_window self];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [_window release];


    //windows設置的根視圖是LoginViewController
    LoginViewController *loginVC = [[LoginViewController alloc] init];
    self.window.rootViewController=loginVC;
    [loginVC release];


    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
//
//  LTView.h
//  UI作業03
//
//  Created by dllo on 15/7/31.
//  Copyright (c) 2015年 zhozhicheng. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface LTView : UIView<UITextFieldDelegate>
//兩個對應的輸入框
@property(nonatomic,retain)UILabel *loadLabel1;
@property(nonatomic,retain)UILabel *loadLabel2;
@property(nonatomic,retain)UITextField *loadTextField1;
@property(nonatomic,retain)UITextField *loadTextField2;

@property(nonatomic,retain)UILabel *confirmLabel;
@property(nonatomic,retain)UILabel *numLabel;
@property(nonatomic,retain)UILabel *emailLabel;
@property(nonatomic,retain)UITextField *confirmTextField;
@property(nonatomic,retain)UITextField *numTextField;
@property(nonatomic,retain)UITextField *emailTextField;
@end
//
//  LTView.m
//  UI作業03
//
//  Created by dllo on 15/7/31.
//  Copyright (c) 2015年 zhozhicheng. All rights reserved.
//

#import "LTView.h"

@implementation LTView

//重寫init方法,模塊化
-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}

-(void)createView
{
    //建立兩個登陸頁面的label視圖
    self.loadLabel1=[[UILabel alloc] initWithFrame:CGRectMake(80, 150, 100, 40)];
    [self addSubview:self.loadLabel1];
    [_loadLabel1 release];

    self.loadLabel2=[[UILabel alloc] initWithFrame:CGRectMake(80, 200, 100, 40)];
    [self addSubview:self.loadLabel2];
    [_loadLabel2 release];
    //建立兩個登陸頁面的textfield
    self.loadTextField1=[[UITextField alloc] initWithFrame:CGRectMake(150, 150, 150, 40)];
    self.loadTextField1.layer.borderWidth=1;
    self.loadTextField1.layer.cornerRadius=10;
    [self addSubview:self.loadTextField1];
     //代理人
    self.loadTextField1.delegate=self;
    [_loadTextField1 release];

    self.loadTextField2=[[UITextField alloc] initWithFrame:CGRectMake(150, 200, 150, 40)];
    self.loadTextField2.layer.borderWidth=1;
    self.loadTextField2.layer.cornerRadius=10;
    [self addSubview:self.loadTextField2];
    //代理人
    self.loadTextField2.delegate=self;
    [_loadTextField2 release];

}

@end
//
//  LoginViewController.m
//  UI作業03
//
//  Created by dllo on 15/7/31.
//  Copyright (c) 2015年 zhozhicheng. All rights reserved.
//

#import "LoginViewController.h"
#import "LTView.h"
#import "RegistViewController.h"
#import "PasswordViewController.h"

@interface LoginViewController ()<UITextFieldDelegate,UIAlertViewDelegate>
@property(nonatomic,retain)UILabel *textlabel;
@property(nonatomic,retain)UIAlertView *alertView;
@property(nonatomic,assign)BOOL isSelected;

@end

@implementation LoginViewController
-(void)dealloc
{

    [_alertView release];
    [_textlabel release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor=[UIColor yellowColor];
    //鋪設登陸頁面的魔化塊
    //建立一個LTView視圖
    LTView *view1=[[LTView alloc] initWithFrame:CGRectMake(0, 0, 350, 500)];
    [self.view addSubview:view1];
    [view1 release];
    //顯示相應的文字
    view1.loadLabel1.text=@"用戶名";
    view1.loadLabel2.text=@"密碼";
    view1.loadTextField1.placeholder=@"請輸入賬號";
    view1.loadTextField2.placeholder=@"請輸入密碼";
    view1.tag = 1000;
    //密碼隱藏
    view1.loadTextField2.secureTextEntry=YES;
    //全部清除按鈕
    view1.loadTextField1.clearButtonMode=UITextFieldViewModeAlways;
    view1.loadTextField2.clearButtonMode=UITextFieldViewModeAlways;
    //回收鍵盤的代理人
    view1.loadTextField1.delegate=self;
    view1.loadTextField2.delegate=self;
    //鋪設三個button
    UIButton *loadButton=[UIButton buttonWithType:UIButtonTypeSystem];
    //BUTTON位置
    loadButton.frame=CGRectMake(70, 300, 50, 25);
    //button文字
    [loadButton setTitle:@"登陸" forState:UIControlStateNormal];
    [self.view addSubview:loadButton];
    //設置button框,圓角
    loadButton.layer.borderWidth=1;
    loadButton.layer.cornerRadius=10;
    //設置button方法
    [loadButton addTarget:self action:@selector(loadClick:) forControlEvents:UIControlEventTouchUpInside];

    UIButton *findButton=[UIButton buttonWithType:UIButtonTypeSystem];
    findButton.frame=CGRectMake(150, 300, 70, 25);
    [findButton setTitle:@"找回密碼" forState:UIControlStateNormal];
    [self.view addSubview:findButton];
    findButton.layer.borderWidth=1;
    findButton.layer.cornerRadius=10;
    [findButton addTarget:self action:@selector(findClick:) forControlEvents:UIControlEventTouchUpInside];

    UIButton *registerButton=[UIButton buttonWithType:UIButtonTypeSystem];
    registerButton.frame=CGRectMake(250, 300, 50, 25);
    [registerButton setTitle:@"註冊" forState:UIControlStateNormal];
    [self.view addSubview:registerButton];
    registerButton.layer.borderWidth=1;
    registerButton.layer.cornerRadius=10;
    [registerButton addTarget:self action:@selector(registerClick:) forControlEvents:UIControlEventTouchUpInside];

    //設置顯示密碼按鈕圖片的更換
    UIButton *picButton=[UIButton buttonWithType:UIButtonTypeCustom];
    picButton.frame=CGRectMake(130,250, 30, 30);
    [picButton setImage:[UIImage imageNamed:@"check.png" ] forState:UIControlStateNormal];
    [self.view addSubview:picButton];
    [picButton addTarget:self action:@selector(changeImage:) forControlEvents:UIControlEventTouchUpInside];
    //文字 顯示內容
    self.textlabel=[[UILabel alloc] initWithFrame:CGRectMake(180, 250, 150, 30)];
    self.textlabel.text=@"顯示內容";
    [self.view addSubview:self.textlabel];
    [self.textlabel release];
    // 報錯
    self.alertView=[[UIAlertView alloc] initWithTitle:@"報錯" message:@"賬號密碼有誤"  delegate:self cancelButtonTitle:@"重新輸入" otherButtonTitles:@"找回密碼", nil];



}
//回收鍵盤的實現,之前需要簽訂協議
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}
//圖片顯示內容切換,
-(void)changeImage:(UIButton *)picButton{
    if (picButton.selected) {
        //切換點擊之後的兩種圖片狀態
        [picButton setImage:[UIImage imageNamed:@"check.png"]  forState:UIControlStateNormal];
    }else{
        [picButton setImage:[UIImage imageNamed:@"checked.png"]  forState:UIControlStateNormal];
    }

    picButton.selected =!picButton.selected;
    ((LTView *)[self.view viewWithTag:1000]).loadTextField2.secureTextEntry ^= 1;
    self.isSelected = !self.isSelected;
}

//判斷賬號密碼的實現
-(void)loadClick:(UIButton *)loadButton
{
    if ( ![((LTView *)[self.view viewWithTag:1000]).loadTextField1.text isEqualToString:@"1104010303"] || ![((LTView *)[self.view viewWithTag:1000]).loadTextField2.text isEqualToString:@"920928"]) {
        [self.alertView show];

    }
}

-(void)findClick:(UIButton *)findButton
{
    RegistViewController *registVC=[[RegistViewController alloc] init];
    [registVC setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    [self presentViewController:registVC animated:YES completion:^{
    }];
    [registVC release];
}

-(void)registerClick:(UIButton *)registerButton
{
    PasswordViewController *passWordVC=[[PasswordViewController alloc] init];
    [passWordVC setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [self presentViewController:passWordVC animated:YES completion:^{
    }];
//    [passWordVC release];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        RegistViewController *registVC = [[RegistViewController alloc] init];
        [registVC setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
        [self presentViewController:registVC animated:YES completion:^{


        }];

    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
//
//  RegistViewController.m
//  UI作業03
//
//  Created by dllo on 15/7/31.
//  Copyright (c) 2015年 zhozhicheng. All rights reserved.
//

#import "RegistViewController.h"


@interface RegistViewController ()<UITextFieldDelegate>
@property(nonatomic,retain)UITextField *emailTextField;

@end

@implementation RegistViewController
-(void)dealloc
{
    [_emailTextField release];
    [super dealloc];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //當前頁面背景
    self.view.backgroundColor=[UIColor cyanColor];
    //建立email輸入框
    self.emailTextField=[[UITextField alloc] initWithFrame:CGRectMake(100, 200, 200, 40)];
    [self.view addSubview:self.emailTextField];
    self.emailTextField.layer.borderWidth=1;
    self.emailTextField.layer.cornerRadius=10;
    self.emailTextField.placeholder=@"電子郵箱";
    //建立此頁面的兩個button
    UIButton *findButton=[UIButton buttonWithType:UIButtonTypeSystem];
    findButton.frame=CGRectMake(120, 280, 40, 25);
    [findButton setTitle:@"找回" forState:UIControlStateNormal];
    [self.view addSubview:findButton];
    findButton.layer.borderWidth=1;
    findButton.layer.cornerRadius=10;
    [findButton addTarget:self action:@selector(findClick:) forControlEvents:UIControlEventTouchUpInside];


    UIButton *abolishButton=[UIButton buttonWithType:UIButtonTypeSystem];
    abolishButton.frame=CGRectMake(200, 280, 40, 25);
    [abolishButton setTitle:@"取消" forState:UIControlStateNormal];
    [self.view addSubview:abolishButton];
    abolishButton.layer.borderWidth=1;
    abolishButton.layer.cornerRadius=10;
    [abolishButton addTarget:self action:@selector(abolishClick:) forControlEvents:UIControlEventTouchUpInside];





}

-(void)abolishClick:(UIButton *)button
{
    [self dismissViewControllerAnimated:YES completion:^{

    }];
}
-(void)findClick:(UIButton *)findButton
{

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
//
//  PasswordViewController.m
//  UI作業03
//
//  Created by dllo on 15/7/31.
//  Copyright (c) 2015年 zhozhicheng. All rights reserved.
//

#import "PasswordViewController.h"
#import "LTView.h"
#import "LoginViewController.h"
#define HEIGHT self.view.frame.size.height
@interface PasswordViewController ()<UITextFieldDelegate,UIAlertViewDelegate>
@property(nonatomic,retain)UILabel *loadLabel1;
@property(nonatomic,retain)UILabel *loadLabel2;
@property(nonatomic,retain)UILabel *confirmLabel;
@property(nonatomic,retain)UILabel *numLabel;
@property(nonatomic,retain)UILabel *emailLabel;
@property(nonatomic,retain)UITextField *loadTextField1;
@property(nonatomic,retain)UITextField *loadTextField2;
@property(nonatomic,retain)UITextField *confirmTextField;
@property(nonatomic,retain)UITextField *numTextField;
@property(nonatomic,retain)UITextField *emailTextField;
@property(nonatomic,retain)UIAlertView *alertView;


@end

@implementation PasswordViewController
-(void)dealloc
{
    [_loadLabel1 release];
    [_loadLabel2 release];
    [_confirmLabel release];
    [_numLabel release];
    [_emailLabel release];
    [_loadTextField1 release];
    [_loadTextField2 release];
    [_confirmTextField release];
    [_numTextField release];
    [_emailTextField release];
    [_alertView release];
    [super dealloc];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.view.backgroundColor=[UIColor redColor];

    self.loadLabel1=[[UILabel alloc] initWithFrame:CGRectMake(60, 150, 70, 40)];
    [self.view addSubview:self.loadLabel1];
    self.loadLabel1.layer.borderWidth = 1;
    self.loadLabel1.layer.cornerRadius =10;
    self.loadLabel1.text=@"用戶名";
    [_loadLabel1 release];

    self.loadLabel2=[[UILabel alloc] initWithFrame:CGRectMake(60, 200, 70, 40)];
    [self.view addSubview:self.loadLabel2];
    self.loadLabel2.layer.borderWidth = 1;
    self.loadLabel2.layer.cornerRadius =10;
    self.loadLabel2.text=@"密碼";
    [_loadLabel2 release];

    self.confirmLabel=[[UILabel alloc] initWithFrame:CGRectMake(60, 250, 70, 40)];
    [self.view addSubview:self.confirmLabel];
    self.confirmLabel.layer.borderWidth = 1;
    self.confirmLabel.layer.cornerRadius =10;
    self.confirmLabel.text=@"確認密碼";
    [_confirmLabel release];

    self.numLabel=[[UILabel alloc] initWithFrame:CGRectMake(60, 300, 70, 40)];
    [self.view addSubview:self.numLabel];
    self.numLabel.layer.borderWidth = 1;
    self.numLabel.layer.cornerRadius =10;
    self.numLabel.text=@"手機號";
    [_numLabel release];

    self.emailLabel=[[UILabel alloc] initWithFrame:CGRectMake(60, 350, 70, 40)];
    [self.view addSubview:self.emailLabel];
    self.emailLabel.layer.borderWidth = 1;
    self.emailLabel.layer.cornerRadius =10;
    self.emailLabel.text=@"郵箱";
    [_emailLabel release];


 // TEXTFIELD

    self.loadTextField1=[[UITextField alloc] initWithFrame:CGRectMake(150, 150, 150, 40)];
    self.loadTextField1.layer.borderWidth=1;
    self.loadTextField1.layer.cornerRadius=10;
    self.loadTextField1.placeholder=@"請輸入用戶名";
    self.loadTextField1.clearButtonMode=UITextFieldViewModeAlways;
    [self.view addSubview:self.loadTextField1];
    //代理人
    self.loadTextField1.delegate=self;
    [_loadTextField1 release];

    self.loadTextField2=[[UITextField alloc] initWithFrame:CGRectMake(150, 200, 150, 40)];
    self.loadTextField2.layer.borderWidth=1;
    self.loadTextField2.layer.cornerRadius=10;
    self.loadTextField2.placeholder=@"請輸入密碼";
    self.loadTextField2.secureTextEntry=YES;
    self.loadTextField2.clearButtonMode=UITextFieldViewModeAlways;
    [self.view addSubview:self.loadTextField2];
    self.loadTextField2.delegate=self;
    [_loadTextField2 release];

    self.confirmTextField=[[UITextField alloc] initWithFrame:CGRectMake(150, 250, 150, 40)];
    self.confirmTextField.layer.borderWidth=1;
    self.confirmTextField.layer.cornerRadius=10;
    self.confirmTextField.placeholder=@"再次輸入密碼";
    self.confirmTextField.secureTextEntry=YES;
    self.confirmTextField.clearButtonMode=UITextFieldViewModeAlways;
    [self.view addSubview:self.confirmTextField];
    self.confirmTextField.delegate=self;
    [_confirmLabel release];


    self.numTextField=[[UITextField alloc] initWithFrame:CGRectMake(150, 300, 150, 40)];
    self.numTextField.layer.borderWidth=1;
    self.numTextField.layer.cornerRadius=10;
    self.numTextField.placeholder=@"請輸入聯繫方式";
    self.numTextField.clearButtonMode=UITextFieldViewModeAlways;
    [self.view addSubview:self.numTextField];
    self.confirmTextField.delegate=self;
    [_numTextField release];


    self.emailTextField=[[UITextField alloc] initWithFrame:CGRectMake(150, 350, 150, 40)];
    self.emailTextField.layer.borderWidth=1;
    self.emailTextField.layer.cornerRadius=10;
    self.emailTextField.placeholder=@"請輸入郵箱";
    self.emailTextField.clearButtonMode=UITextFieldViewModeAlways;
    [self.view addSubview:self.emailTextField];
    self.emailTextField.delegate=self;
    [_emailTextField release];

    //註冊按鈕
    UIButton *registerButton=[UIButton buttonWithType:UIButtonTypeSystem];
    registerButton.frame=CGRectMake(110, 460, 50, 25);
    [registerButton setTitle:@"註冊" forState:UIControlStateNormal];
    [self.view addSubview:registerButton];
    registerButton.layer.borderWidth=1;
    registerButton.layer.cornerRadius=10;
    [registerButton addTarget:self action:@selector(registerClick:) forControlEvents:UIControlEventTouchUpInside];



    //取消按鈕
    UIButton *cancelButton=[UIButton buttonWithType:UIButtonTypeSystem];
    cancelButton.frame=CGRectMake(200, 460, 50, 25);
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [self.view addSubview:cancelButton];
    cancelButton.layer.borderWidth=1;
    cancelButton.layer.cornerRadius=10;
    [cancelButton addTarget:self action:@selector(cancelClick:) forControlEvents:UIControlEventTouchUpInside];


    self.alertView=[[UIAlertView alloc] initWithTitle:@"恭喜" message:@"註冊成功" delegate:self cancelButtonTitle:@"返回登陸頁面" otherButtonTitles:@"取消", nil];

}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if (textField.frame.origin.y > HEIGHT / 2) {
        //先做一個差值
        CGFloat height =textField.frame.origin.y- HEIGHT / 2;
        self.view.center=CGPointMake(self.view.center.x, self.view.center.y - height);
    }
    return YES;
}
// 等到編譯結束的時候,再讓他回到原位
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    if (textField.frame.origin.y > HEIGHT / 2) {
        CGFloat height =textField.frame.origin.y- HEIGHT / 2;
        self.view.center=CGPointMake(self.view.center.x, self.view.center.y + height);
    }
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

-(void)cancelClick:(UIButton *)cancelButton
{
    [self dismissViewControllerAnimated:YES completion:^{

    }];
}

-(void)registerClick:(UIButton *)button
{
    [self.alertView show];

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        LoginViewController *loginVC = [[LoginViewController alloc] init];
        [loginVC setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
        [self presentViewController:loginVC animated:YES completion:^{


        }];
        [loginVC release];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章