运用UI制作简单的 登陆系统

来源:互联网 发布:mac长的破折号怎么打 编辑:程序博客网 时间:2024/04/30 06:43

//

//  AppDelegate.h

//  UI-Homework-5

//

//  Created by lanouhn on 15-7-31.

//  Copyright (c) 2015 尹江涛. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface AppDelegate :UIResponder <UIApplicationDelegate>


@property (strong,nonatomic) UIWindow *window;



@end


//

//  AppDelegate.m

//  UI-Homework-5

//

//  Created by lanouhn on 15-7-31.

//  Copyright (c) 2015 尹江涛. All rights reserved.

//


#import "AppDelegate.h"

#import "DelegateViewController.h"

#import "LoginViewController.h"

@interface AppDelegate ()


@end


@implementation AppDelegate



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

    self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColorwhiteColor];

    [self.windowmakeKeyAndVisible];

    

//    DelegateViewController *delegateVC = [[DelegateViewController alloc] init];

//    

//    self.window.rootViewController = delegateVC;

//    

//    [delegateVC release];

    

    LoginViewController *loginVC = [[LoginViewControlleralloc] init];

    

    self.window.rootViewController = loginVC;

    

    [loginVCrelease];

    

    

    

    

    return YES;

}


//键盘回收

- (BOOL)textFieldShouldReturn:(UITextField *)textField

{

    

    //ltview.textField的键盘回收

    //ltview准备一个让键盘回收的方法

    [((LTView *)self.window.subviews[0])resignKeybord];

    

    

    

    NSLog(@"keybord");

    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



//

//  LoginViewController.h

//  UI-Homework-5

//

//  Created by lanouhn on 15-8-1.

//  Copyright (c) 2015 尹江涛. All rights reserved.

//


#import <UIKit/UIKit.h>

#import "LoginView.h"

@interface LoginViewController :UIViewController


//创建一个登陆界面View

@property (nonatomic ,retain)LoginView *loginView;


//创建可变字典用来保存账号和密码

@property (nonatomic ,retain)NSMutableDictionary *dic;


//外界获取字典

- (NSMutableDictionary *)dic;


@end



//

//  LoginViewController.m

//  UI-Homework-5

//

//  Created by lanouhn on 15-8-1.

//  Copyright (c) 2015 尹江涛. All rights reserved.

//


#import "LoginViewController.h"

#import "RegisterViewController.h"

#import "FindPwdViewController.h"

@interface LoginViewController ()


@end


@implementation LoginViewController

- (void)loadView

{

    [superloadView];

    

    self.loginView = [[LoginViewalloc] initWithFrame:[UIScreenmainScreen].bounds];

    

   self.view =self.loginView;

    

    [self.loginViewrelease];

    

    

}


//添加点击按钮的方法

- (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view.

    //账号和密码保存到字典中

    _dic = [@{@"111":@"222"}mutableCopy];

    

    //确认登陆confirm 取消登录cancel  找回密码findPwd  去注册registerButton

    [self.loginView.confirmButtonaddTarget:selfaction:@selector(confirmButtonAction:)forControlEvents:UIControlEventTouchUpInside];

    

    [self.loginView.cancelButtonaddTarget:selfaction:@selector(cancelButtonAction:)forControlEvents:UIControlEventTouchUpInside];

    

    [self.loginView.findPwdButtonaddTarget:selfaction:@selector(findPwdButtonAction:)forControlEvents:UIControlEventTouchUpInside];

    

    [self.loginView.registerButtonaddTarget:selfaction:@selector(registerButtonAction:)forControlEvents:UIControlEventTouchUpInside];

    

}

#pragma mark - 点击按钮的响应事件

#pragma mark - 确认登陆

- (void)confirmButtonAction:(UIButton *)sender

{

    NSLog(@"%@",self.dic);

    //判断用户名和密码其中之一是否为空

   BOOL result = NO;

   if ([self.loginView.userNamegetTextField].length ==0 && [self.loginView.passwordgetTextField].length ==0  ) {

        UIAlertView *view = [[UIAlertViewalloc] initWithTitle:@"错误提示"message:@"账号或密码不能为空"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];

        [viewshow];

        [viewrelease];

        result =YES;

    }

    //判断用户名和密码是否匹配

   if (result == NO) {

       BOOL isHave = NO;

       for (NSString *keyin [_dic allKeys]) {

           if ([[self.loginView.userNamegetTextField] isEqualToString:key]) {

               if ([[self.loginView.passwordgetTextField] isEqualToString:[_dicobjectForKey:key]]) {

                    isHave =YES;

                }

            }

        }

       if (isHave == NO) {

            UIAlertView *view = [[UIAlertViewalloc] initWithTitle:@"登录成功"message:@"欢迎回来"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];

            

            [viewshow];

            [viewrelease];

        }else {

            UIAlertView *view = [[UIAlertViewalloc] initWithTitle:@"登录失败"message:@"输入的账号和密码不匹配,请核实一下后,重新输入"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];

            [viewshow];

            [viewrelease];

        }

    }

}

#pragma mark - 取消登陆

- (void)cancelButtonAction:(UIButton *)sender

{

    

    NSLog(@"取消按钮被点击");

    

}

#pragma mark - 找回密码

- (void)findPwdButtonAction:(UIButton *)sender

{

    NSLog(@"找回密码被点击");

    

    //先创建注册控制器的对象

    FindPwdViewController *findPwdVC = [[FindPwdViewControlleralloc] init];

    

    //用当前的控制器模态(也就是推过去的意思)到 registVC

    [selfpresentViewController:findPwdVC animated:YEScompletion:nil];

    

}

#pragma mark - 去注册

- (void)registerButtonAction:(UIButton *)sender

{

    

    NSLog(@"注册按钮被点击");

    RegisterViewController *registerVC = [[RegisterViewControlleralloc] init];

    

    [selfpresentViewController:registerVC animated:YEScompletion:nil];

    

    

}

//外界获取字典

- (NSMutableDictionary *)dic

{

   return _dic;

}



- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // 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.

}

*/


- (void)dealloc

{

    [_loginView release];

    [superdealloc];

}


@end



//

//  LoginView.h

//  UI-Homework-5

//

//  Created by lanouhn on 15-8-1.

//  Copyright (c) 2015 尹江涛. All rights reserved.

//


#import <UIKit/UIKit.h>

#import "LTView.h"

@interface LoginView :UIView


//用户名userName  密码password  确认登陆confirm 取消登录cancel  找回密码findPwd  去注册registerButton

//用户名

@property (nonatomic ,retain )LTView *userName;

//密码

@property (nonatomic ,retain)LTView *password;

//确认登陆

@property (nonatomic ,retain)UIButton *confirmButton;

//取消登陆

@property (nonatomic ,retain )UIButton *cancelButton;

//找回密码

@property (nonatomic ,retain )UIButton *findPwdButton;

//去注册

@property (nonatomic ,retain)UIButton *registerButton;



@end



//

//  LoginView.m

//  UI-Homework-5

//

//  Created by lanouhn on 15-8-1.

//  Copyright (c) 2015 尹江涛. All rights reserved.

//


#import "LoginView.h"


@implementation LoginView


/*

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

    // Drawing code

}

*/


- (instancetype)initWithFrame:(CGRect)frame

{

   self = [superinitWithFrame:frame];

   if (self) {

        [selfaddSubviews];

    }

    return self;

    

}

#pragma mark - 添加view的内容

- (void)addSubviews

{

    //用户名userName 密码password  确认登陆confirm  取消登录cancel 找回密码findPwd  去注册registerButton

    

    //用户名

    self.userName = [selfcreateLTViewWithFrame:CGRectMake(30,45, 250, 30)andLabelTitle:@"用户名"andPlacehodle:@"请输入用户名"];

    

    [selfaddSubview:self.userName];

    

    

   //密码

    self.password = [selfcreateLTViewWithFrame:CGRectMake(30,80, 250, 30)andLabelTitle:@"密码"andPlacehodle:@"请输入密码"];

    [selfaddSubview:self.password];

    self.password.textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;


    

   //登陆

    self.confirmButton = [selfcreateButtonWithFrame:CGRectMake(45,120, 90, 30)andTitleLabel:@"确认登陆"];

    [selfaddSubview:self.confirmButton];

    

   //注册

    self.registerButton = [selfcreateButtonWithFrame:CGRectMake(140,120, 90, 30)andTitleLabel:@"注册"];

    [selfaddSubview:self.registerButton];

    

   //取消

    self.cancelButton = [selfcreateButtonWithFrame:CGRectMake(45,160, 90, 30)andTitleLabel:@"取消"];

    [selfaddSubview:self.cancelButton];

    

    //找回密码

    self.findPwdButton = [selfcreateButtonWithFrame:CGRectMake(140,160, 90, 30)andTitleLabel:@"找回密码"];

    [selfaddSubview:self.findPwdButton];


    

    

}


#pragma mark - 创建button的工厂方法

- (UIButton *)createButtonWithFrame:(CGRect )frame

                      andTitleLabel:(NSString *)titleLabel

{

    UIButton *button = [UIButtonbuttonWithType:UIButtonTypeSystem];

    

    button.frame = frame;

    

    [button setTitle:titleLabelforState:UIControlStateNormal];

    

   return button ;

}

#pragma mark - 创建ltview的工厂方法

- (LTView *)createLTViewWithFrame:(CGRect )frame

                    andLabelTitle:(NSString *)labelTitle

                    andPlacehodle:(NSString *)placehodle

{

    

   LTView *ltView = [[LTViewalloc] initWithFrame:frame];

    

    [ltViewgiveLabelText:labelTitle];

    

    [ltViewgiveTextFieldPlaceholder:placehodle];

    

   return  [ltView autorelease];

    

}


- (void)dealloc

{

    [_userName release];

    [_password release];

    [_confirmButtonrelease];

    [_cancelButtonrelease];

    [_findPwdButtonrelease];

    [_registerButtonrelease];

    

    [superdealloc];

}

@end



//

//  RegisterViewController.h

//  UI-Homework-5

//

//  Created by lanouhn on 15-8-1.

//  Copyright (c) 2015 尹江涛. All rights reserved.

//


#import <UIKit/UIKit.h>

#import "RegisterView.h"

#import "LoginViewController.h"

@interface RegisterViewController :UIViewController



@property (nonatomic ,retain)RegisterView *registerView;

//保存注册的账号和密码

@property (nonatomic ,retain)LoginViewController *loginVC;


@end


//

//  RegisterViewController.m

//  UI-Homework-5

//

//  Created by lanouhn on 15-8-1.

//  Copyright (c) 2015 尹江涛. All rights reserved.

//


#import "RegisterViewController.h"


@interface RegisterViewController ()


@end


@implementation RegisterViewController


- (void)loadView

{

    [superloadView];

    

    self.registerView = [[RegisterViewalloc] initWithFrame:[UIScreenmainScreen].bounds];

    

    self.view =self.registerView;

    

    [self.registerViewrelease];

    

}



- (void)viewDidLoad {

    [superviewDidLoad];


    //确定注册

    [self.registerView.confirmButtonaddTarget:selfaction:@selector(confirmButtonAction:)forControlEvents:UIControlEventTouchUpInside];

    //取消注册

    [self.registerView.cancelButtonaddTarget:selfaction:@selector(cancelButtonAction:)forControlEvents:UIControlEventTouchUpInside];

    

    

    // Do any additional setup after loading the view.

}

#pragma mark = 确定按钮点击事件

- (void)confirmButtonAction:(UIButton *)sender

{

    NSLog(@"确定注册按钮被点击");

    //判断用户名密码 和重新输入的密码是否为空

   BOOL isHave = NO;

    if ([self.registerView.userNamegetTextField].length ==0 && [self.registerView.passwordgetTextField].length ==0 && [self.registerView.confirmPasswordgetTextField].length ==0) {

        

        UIAlertView *view = [[UIAlertViewalloc] initWithTitle:@"错误提示"message:@"用户名和密码不能为空"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定 ",nil];

        [viewshow];

        [viewrelease];

        

    }else {

        //判断用户名是否已存在

        //遍历字典中内容

       for (NSString *keyin [self.loginVC.dicallKeys]) {

           if ([[self.registerView.userNamegetTextField] isEqualToString:key]) {

                

                UIAlertView *view = [[UIAlertViewalloc] initWithTitle:@"错误提示"message:@"该用户名已经被注册,请输入一个新的用户名"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定 ",nil];

                [viewshow];

                [viewrelease];

                isHave =YES;

            }

        }

    }

   if (isHave == NO) {

        //判断两次输入的密码是否一致

        if (![[self.registerView.passwordgetTextField]isEqualToString:[self.registerView.confirmPasswordgetTextField]]) {

            

            UIAlertView *view = [[UIAlertViewalloc] initWithTitle:@"错误提示"message:@"两次输入的密码不一样"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定 ",nil];

            [viewshow];

            [viewrelease];

            

        }else {

            //将注册的账号和密码添加到字典中

            [self.loginVC.dicsetObject:[self.registerView.passwordgetTextField]forKey:[self.registerView.userNamegetTextField]];

            

            UIAlertView *view = [[UIAlertViewalloc] initWithTitle:@"注册成功"message:@"欢迎加入本网站"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定 ",nil];

            [viewshow];

            [viewrelease];

        }

        

    }

   

     [selfdismissViewControllerAnimated:YEScompletion:nil];

}


#pragma mark - 取消按钮点击事件


- (void)cancelButtonAction:(UIButton *)sender

{

   NSLog(@"取消注册");

    

    [selfdismissViewControllerAnimated:YEScompletion:nil];

}



- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

- (void)dealloc

{

    [_registerViewrelease];

    [superdealloc];

}



/*

#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



//

//  RegisterView.h

//  UI-Homework-5

//

//  Created by lanouhn on 15-8-1.

//  Copyright (c) 2015 尹江涛. All rights reserved.

//


#import <UIKit/UIKit.h>

#import "LTView.h"

@interface RegisterView :UIView



//用户名 密码 确认密码 手机号 邮箱地址 确定 取消

//用户名

@property (nonatomic ,retain) LTView *userName;


//密码

@property (nonatomic ,retain)LTView *password;

//确认密码

@property (nonatomic ,retain) LTView *confirmPassword;

//手机号

@property (nonatomic ,retain)LTView *telephone;

//邮箱地址

@property (nonatomic ,retain)LTView *email;

//按钮

//确定

@property (nonatomic ,retain) UIButton *confirmButton;

//取消

@property (nonatomic ,retain)UIButton *cancelButton;



@end


//

//  RegisterView.m

//  UI-Homework-5

//

//  Created by lanouhn on 15-8-1.

//  Copyright (c) 2015 尹江涛. All rights reserved.

//


#import "RegisterView.h"


@implementation RegisterView


- (instancetype)initWithFrame:(CGRect)frame

{

   self = [superinitWithFrame:frame];

   if (self) {

       [selfaddSubviews] ;

    }

    return self;

}

#pragma mark - 添加控件

- (void)addSubviews

{

    

    //用户名userName密码password 确认密码confirmPassword 手机号 邮箱地址 确定confirmButton 取消

    self.userName = [selfcreateLTViewWithFrame:CGRectMake(30,50, 250, 30)andLabelTitle:@"用户名"andPlacehodle:@"请输入用户名"];

    [selfaddSubview:self.userName];

    

    self.password = [selfcreateLTViewWithFrame:CGRectMake(30,85, 250, 30)andLabelTitle:@"密码"andPlacehodle:@"请输入密码"];

    self.password.textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

    [selfaddSubview:self.password];

    

    self.confirmPassword = [selfcreateLTViewWithFrame:CGRectMake(30,120, 250, 30)andLabelTitle:@"确认密码"andPlacehodle:@"请重新输入密码"];

    self.confirmPassword.textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

    [selfaddSubview:self.confirmPassword];

    

    self.telephone = [selfcreateLTViewWithFrame:CGRectMake(30,155, 250, 30)andLabelTitle:@"电话号码"andPlacehodle:@"请输入你的电话号码"];

    self.telephone.textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

    [selfaddSubview:self.telephone];

    

    self.email = [selfcreateLTViewWithFrame:CGRectMake(30,190, 250, 30)andLabelTitle:@"邮箱地址"andPlacehodle:@"请输入邮箱地址"];

    [selfaddSubview:self.email];

    

    self.confirmButton = [selfcreateButtonWithFrame:CGRectMake(60,230, 60, 30)andTitleLabel:@"确认注册"];

    [selfaddSubview:self.confirmButton];

    

    self.cancelButton = [selfcreateButtonWithFrame:CGRectMake(130,230, 60, 30)andTitleLabel:@"取消注册"];

    [selfaddSubview:self.cancelButton];

    

    

}

#pragma mark - 创建button的工厂方法

- (UIButton *)createButtonWithFrame:(CGRect )frame

                      andTitleLabel:(NSString *)titleLabel

{

    UIButton *button = [UIButtonbuttonWithType:UIButtonTypeSystem];

    

    button.frame = frame;

    

    [button setTitle:titleLabelforState:UIControlStateNormal];

    

   return button ;

}

#pragma mark - 创建ltview的工厂方法

- (LTView *)createLTViewWithFrame:(CGRect )frame

                    andLabelTitle:(NSString *)labelTitle

                    andPlacehodle:(NSString *)placehodle

{

    

   LTView *ltView = [[LTViewalloc] initWithFrame:frame];

    

    [ltViewgiveLabelText:labelTitle];

    

    [ltViewgiveTextFieldPlaceholder:placehodle];

    

   return  [ltView autorelease];

    

}


- (void)dealloc

{

    [_userName release];

    [_password release];

    [_confirmPasswordrelease];

    [_telephone release];

    [_emailrelease];

    [_confirmButtonrelease];

    [_cancelButtonrelease];

    [superdealloc];

}



/*

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

    // Drawing code

}

*/


@end


//

//  FindPwdViewController.h

//  UI-Homework-5

//

//  Created by lanouhn on 15-8-1.

//  Copyright (c) 2015 尹江涛. All rights reserved.

//


#import <UIKit/UIKit.h>

#import "FindPwdView.h"

@interface FindPwdViewController :UIViewController


@property (nonatomic ,retain)FindPwdView *findPwdView;


@end


//

//  FindPwdViewController.m

//  UI-Homework-5

//

//  Created by lanouhn on 15-8-1.

//  Copyright (c) 2015 尹江涛. All rights reserved.

//


#import "FindPwdViewController.h"

#import "RegisterViewController.h"

#import "LoginViewController.h"

@interface FindPwdViewController ()


@end


@implementation FindPwdViewController


- (void)loadView

{

    [superloadView];

    

    self.findPwdView = [[FindPwdViewalloc] initWithFrame:[UIScreenmainScreen].bounds];

    

    self.view =self.findPwdView;

    

    [self.findPwdViewrelease];

    

}


- (void)viewDidLoad {

    [superviewDidLoad];

    

    //点击按钮响应事件

   //确定

    [self.findPwdView.confirmButtonaddTarget:selfaction:@selector(certainButtonAction:)forControlEvents:UIControlEventTouchUpInside];


   //取消

    [self.findPwdView.cancelButtonaddTarget:selfaction:@selector(cancelButtonAction:)forControlEvents:UIControlEventTouchUpInside];

    

   //注册

    [self.findPwdView.registerButtonaddTarget:selfaction:@selector(registerButtonAction:)forControlEvents:UIControlEventTouchUpInside];

    

    

   //登陆

    

    [self.findPwdView.loginButtonaddTarget:selfaction:@selector(loginButtonAction:)forControlEvents:UIControlEventTouchUpInside];

    

}


#pragma mark - 确定按钮点击事件

- (void)certainButtonAction:(UIButton *)sender

{

    NSLog(@"验证码已发送到你的邮箱,请注意查收,如果不是本人操作,请勿回复!");

    

    NSLog(@"登陆按钮被点击");

    if ([self.findPwdView.userNamegetTextField].length ==0 || [self.findPwdView.telePhonegetTextField] ==0) {

        UIAlertView *view = [[UIAlertViewalloc] initWithTitle:@"警告"message:@"用户名或手机号不能为空"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];

        [viewshow];

        [viewrelease];

    }else {

       //验证成功

        UIAlertView *view = [[UIAlertViewalloc] initWithTitle:@"提示"message:@"验证码已经发送到绑定的手机号或者邮箱中,请注意查收"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];

        

        

        

        [viewshow];

        [viewrelease];

    }

}


#pragma mark - 取消按钮点击事件

- (void)cancelButtonAction:(UIButton *)sender

{

    [selfdismissViewControllerAnimated:YEScompletion:nil];

}


#pragma mark - 返回登陆按钮点击事件

- (void)loginButtonAction:(UIButton *)sender

{

    [selfdismissViewControllerAnimated:YEScompletion:nil];

    

}


#pragma mark - 注册按钮点击事件


- (void)registerButtonAction:(UIButton *)sender

{

    //先创建注册控制器的对象

    RegisterViewController *registerVC = [[RegisterViewControlleralloc] init];

    

    //用当前的控制器模态(也就是推过去的意思)到 registerVC

    [selfpresentViewController:registerVC animated:YEScompletion:nil];

    

}


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

   if ([self isViewLoaded] == YES && self.view.window ==nil) {

       self.view =nil;

        NSLog(@"!我被释放掉了");

    }


    // Dispose of any resources that can be recreated.

}


- (void)dealloc

{

    

    [_findPwdView release];

    [superdealloc];

}


/*

#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


//

//  FindPwdView.h

//  UI-Homework-5

//

//  Created by lanouhn on 15-8-1.

//  Copyright (c) 2015 尹江涛. All rights reserved.

//


#import <UIKit/UIKit.h>

#import "LTView.h"

@interface FindPwdView :UIView


//用户名 手机号 确定 取消 返回登陆 去注册

//用户名

@property (nonatomic ,retain)LTView *userName;


//手机号

@property (nonatomic ,retain)LTView *telePhone;


//邮箱地址

@property (nonatomic ,retain)LTView *email;

//确定

@property (nonatomic ,retain)UIButton *confirmButton;

//取消

@property (nonatomic ,retain)UIButton *cancelButton;

//返回登陆

@property (nonatomic ,retain)UIButton *loginButton;

//去注册

@property (nonatomic ,retain)UIButton *registerButton;


@end


//

//  FindPwdView.m

//  UI-Homework-5

//

//  Created by lanouhn on 15-8-1.

//  Copyright (c) 2015 尹江涛. All rights reserved.

//


#import "FindPwdView.h"


@implementation FindPwdView


- (instancetype)initWithFrame:(CGRect)frame

{

   self = [superinitWithFrame:frame];

   if (self) {

        

        [selfaddSubviews];

    }

    return self;

}

#pragma mark - 添加控件

- (void)addSubviews

{

    

    //用户名userName手机号 邮箱地址 确定confirmButton 取消

    self.userName = [selfcreateLTViewWithFrame:CGRectMake(30,50, 250, 30)andLabelTitle:@"用户名"andPlacehodle:@"请输入用户名"];

    [selfaddSubview:self.userName];

    

    self.telePhone = [selfcreateLTViewWithFrame:CGRectMake(30,85, 250, 30)andLabelTitle:@"电话号码"andPlacehodle:@"请输入你的电话号码"];

    self.telePhone.textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

    [selfaddSubview:self.telePhone];

    

    self.email = [selfcreateLTViewWithFrame:CGRectMake(30,120, 250, 30)andLabelTitle:@"邮箱地址"andPlacehodle:@"请输入邮箱地址"];

    [selfaddSubview:self.email];

    

    self.confirmButton = [selfcreateButtonWithFrame:CGRectMake(55,160, 60, 30)andTitleLabel:@"确认"];

    [selfaddSubview:self.confirmButton];

    

    self.cancelButton = [selfcreateButtonWithFrame:CGRectMake(130,160, 60, 30)andTitleLabel:@"取消"];

    [selfaddSubview:self.cancelButton];

    

    

}

#pragma mark - 创建button的工厂方法

- (UIButton *)createButtonWithFrame:(CGRect )frame

                      andTitleLabel:(NSString *)titleLabel

{

    UIButton *button = [UIButtonbuttonWithType:UIButtonTypeSystem];

    

    button.frame = frame;

    

    [button setTitle:titleLabelforState:UIControlStateNormal];

    

   return button ;

}

#pragma mark - 创建ltview的工厂方法

- (LTView *)createLTViewWithFrame:(CGRect )frame

                    andLabelTitle:(NSString *)labelTitle

                    andPlacehodle:(NSString *)placehodle

{

    

   LTView *ltView = [[LTViewalloc] initWithFrame:frame];

    

    [ltViewgiveLabelText:labelTitle];

    

    [ltViewgiveTextFieldPlaceholder:placehodle];

    

   return  [ltView autorelease];

    

}


- (void)dealloc

{

    [_userName release];

    [_telePhone release];

    [_emailrelease];

    [_confirmButtonrelease];

    [_cancelButtonrelease];

    [superdealloc];

}



/*

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

    // Drawing code

}

*/


@end



//

//  LTView.h

//  UI-Homework-5

//

//  Created by lanouhn on 15-8-1.

//  Copyright (c) 2015 尹江涛. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface LTView :UIView


//给外界提供getter的方法

- (void)giveLabelText:(NSString *)text;

//给外界提供设置label的颜色

- (void)giveLabelColor:(UIColor *)color;

//输入框占位符

- (void)giveTextFieldPlaceholder:(NSString *)placeholder;

//设置TextField代理

- (void)giveTextFieldDelegate:(id)object;

//回收键盘

- (void)resignKeybord;

//给外界提供改变内部两个控件frame的方法

- (void)alertLtViewFrame:(CGRect)frame;

//给外界提供textField的内容的方法

- (NSString *)getTextField;


//给外界提供得到textField的方法

- (UITextField *)textField;



@end



//

//  LTView.m

//  UI-Homework-5

//

//  Created by lanouhn on 15-8-1.

//  Copyright (c) 2015 尹江涛. All rights reserved.

//


#import "LTView.h"


@interface LTView ()

//私有属性

//label

@property (nonatomic ,retain)UILabel *label;


//textField

@property (nonatomic ,retain)UITextField *textField;



@end



@implementation LTView


/*

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

    // Drawing code

}

*/

- (instancetype)initWithFrame:(CGRect)frame

{

   self = [superinitWithFrame:frame];

   if (self) {

        //添加label

       self.label = [[UILabelalloc] initWithFrame:CGRectMake(0,0, frame.size.width *2/5, frame.size.height )];

       self.label.backgroundColor = [UIColorwhiteColor];

        [selfaddSubview:self.label];

        [self.labelrelease];

        

        //添加textField

       //输入框

       self.textField = [[UITextFieldalloc] initWithFrame:CGRectMake(frame.size.width *2/5, 0, frame.size.width *3/5, frame.size.height)];

       self.textField.backgroundColor = [UIColorlightTextColor];

        //输入框的边框圆角 边框边框颜色  边框半径

        self.textField.borderStyle = UITextBorderStyleRoundedRect;

        self.textField.layer.borderWidth = 1;

       self.textField.layer.borderColor = [[UIColorblueColor]CGColor];

        self.textField.layer.cornerRadius = 10;

        //输入框的清空设置

        self.textField.clearsOnBeginEditing =YES;

        self.textField.clearButtonMode = UITextFieldViewModeAlways;

        //改变键盘的return的类型

        self.textField.keyboardType = UIReturnKeyNext;

        

        [selfaddSubview:self.textField];

        [self.textFieldrelease];

        

    }

    return self;

}


#pragma mark - 给外界提供getter的方法

- (void)giveLabelText:(NSString *)text

{

   self.label.text = text;

}


- (void)giveLabelColor:(UIColor *)color

{

   self.label.backgroundColor = color;

}


- (void)giveTextFieldPlaceholder:(NSString *)placeholder

{

   self.textField.placeholder = placeholder;

}


- (void)giveTextFieldDelegate:(id)object

{

   self.textField.delegate = object;

}


- (void)resignKeybord

{

    [self.textFieldresignFirstResponder];

    

}

//给外界提供改变内部两个控件frame的方法

- (void)alertLtViewFrame:(CGRect)frame

{

   self.label.frame =CGRectMake(0,0, frame.size.width /3, frame.size.height);

   self.textField.frame =CGRectMake(frame.size.width /3, 0, frame.size.width *2 / 3, frame.size.height);

}


//给外界提供textField的内容的方法

- (NSString *)getTextField

{

   NSString *str = self.textField.text;

   return str;

}


//给外界提供得到textField的方法

- (UITextField *)textField

{

    return_textField;

}


- (void)dealloc

{

    [_labelrelease];

    [_textField release];

    

    [superdealloc];

}


@end



0 0
原创粉丝点击