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

3 篇文章 0 订阅

//

//  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 = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    

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

//    

//    self.window.rootViewController = delegateVC;

//    

//    [delegateVC release];

    

    LoginViewController *loginVC = [[LoginViewController alloc] init];

    

    self.window.rootViewController = loginVC;

    

    [loginVC release];

    

    

    

    

    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

{

    [super loadView];

    

    self.loginView = [[LoginView alloc] initWithFrame:[UIScreen mainScreen].bounds];

    

    self.view = self.loginView;

    

    [self.loginView release];

    

    

}


//添加点击按钮的方法

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

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

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

    

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

    [self.loginView.confirmButton addTarget:self action:@selector(confirmButtonAction:) forControlEvents:UIControlEventTouchUpInside];

    

    [self.loginView.cancelButton addTarget:self action:@selector(cancelButtonAction:) forControlEvents:UIControlEventTouchUpInside];

    

    [self.loginView.findPwdButton addTarget:self action:@selector(findPwdButtonAction:) forControlEvents:UIControlEventTouchUpInside];

    

    [self.loginView.registerButton addTarget:self action:@selector(registerButtonAction:) forControlEvents:UIControlEventTouchUpInside];

    

}

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

#pragma mark - 确认登陆

- (void)confirmButtonAction:(UIButton *)sender

{

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

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

    BOOL result = NO;

    if ([self.loginView.userName getTextField].length == 0 && [self.loginView.password getTextField].length == 0  ) {

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

        [view show];

        [view release];

        result = YES;

    }

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

    if (result == NO) {

        BOOL isHave = NO;

        for (NSString *key in [_dic allKeys]) {

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

                if ([[self.loginView.password getTextField] isEqualToString:[_dic objectForKey:key]]) {

                    isHave = YES;

                }

            }

        }

        if (isHave == NO) {

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

            

            [view show];

            [view release];

        } else {

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

            [view show];

            [view release];

        }

    }

}

#pragma mark - 取消登陆

- (void)cancelButtonAction:(UIButton *)sender

{

    

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

    

}

#pragma mark - 找回密码

- (void)findPwdButtonAction:(UIButton *)sender

{

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

    

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

    FindPwdViewController *findPwdVC = [[FindPwdViewController alloc] init];

    

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

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

    

}

#pragma mark - 去注册

- (void)registerButtonAction:(UIButton *)sender

{

    

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

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

    

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

    

    

}

//外界获取字典

- (NSMutableDictionary *)dic

{

    return _dic;

}



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

}

*/


- (void)dealloc

{

    [_loginView release];

    [super dealloc];

}


@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 = [super initWithFrame:frame];

    if (self) {

        [self addSubviews];

    }

    return self;

    

}

#pragma mark - 添加view的内容

- (void)addSubviews

{

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

    

    //用户名

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

    

    [self addSubview:self.userName];

    

    

    //密码

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

    [self addSubview:self.password];

    self.password.textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;


    

    //登陆

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

    [self addSubview:self.confirmButton];

    

    //注册

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

    [self addSubview:self.registerButton];

    

    //取消

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

    [self addSubview:self.cancelButton];

    

    //找回密码

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

    [self addSubview:self.findPwdButton];


    

    

}


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

- (UIButton *)createButtonWithFrame:(CGRect )frame

                      andTitleLabel:(NSString *)titleLabel

{

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

    

    button.frame = frame;

    

    [button setTitle:titleLabel forState:UIControlStateNormal];

    

    return button ;

}

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

- (LTView *)createLTViewWithFrame:(CGRect )frame

                    andLabelTitle:(NSString *)labelTitle

                    andPlacehodle:(NSString *)placehodle

{

    

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

    

    [ltView giveLabelText:labelTitle];

    

    [ltView giveTextFieldPlaceholder:placehodle];

    

    return  [ltView autorelease];

    

}


- (void)dealloc

{

    [_userName release];

    [_password release];

    [_confirmButton release];

    [_cancelButton release];

    [_findPwdButton release];

    [_registerButton release];

    

    [super dealloc];

}

@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

{

    [super loadView];

    

    self.registerView = [[RegisterView alloc] initWithFrame:[UIScreen mainScreen].bounds];

    

    self.view = self.registerView;

    

    [self.registerView release];

    

}



- (void)viewDidLoad {

    [super viewDidLoad];


    //确定注册

    [self.registerView.confirmButton addTarget:self action:@selector(confirmButtonAction:) forControlEvents:UIControlEventTouchUpInside];

    //取消注册

    [self.registerView.cancelButton addTarget:self action:@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.userName getTextField].length == 0 && [self.registerView.password getTextField].length == 0 && [self.registerView.confirmPassword getTextField].length == 0) {

        

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

        [view show];

        [view release];

        

    } else {

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

        //遍历字典中内容

        for (NSString *key in [self.loginVC.dic allKeys]) {

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

                

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

                [view show];

                [view release];

                isHave = YES;

            }

        }

    }

    if (isHave == NO) {

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

        if (![[self.registerView.password getTextField] isEqualToString:[self.registerView.confirmPassword getTextField]]) {

            

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

            [view show];

            [view release];

            

        } else {

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

            [self.loginVC.dic setObject:[self.registerView.password getTextField] forKey:[self.registerView.userName getTextField]];

            

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

            [view show];

            [view release];

        }

        

    }

   

     [self dismissViewControllerAnimated:YES completion:nil];

}


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


- (void)cancelButtonAction:(UIButton *)sender

{

    NSLog(@"取消注册");

    

    [self dismissViewControllerAnimated:YES completion:nil];

}



- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

- (void)dealloc

{

    [_registerView release];

    [super dealloc];

}



/*

#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 = [super initWithFrame:frame];

    if (self) {

       [self addSubviews] ;

    }

    return self;

}

#pragma mark - 添加控件

- (void)addSubviews

{

    

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

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

    [self addSubview:self.userName];

    

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

    self.password.textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

    [self addSubview:self.password];

    

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

    self.confirmPassword.textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

    [self addSubview:self.confirmPassword];

    

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

    self.telephone.textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

    [self addSubview:self.telephone];

    

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

    [self addSubview:self.email];

    

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

    [self addSubview:self.confirmButton];

    

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

    [self addSubview:self.cancelButton];

    

    

}

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

- (UIButton *)createButtonWithFrame:(CGRect )frame

                      andTitleLabel:(NSString *)titleLabel

{

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

    

    button.frame = frame;

    

    [button setTitle:titleLabel forState:UIControlStateNormal];

    

    return button ;

}

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

- (LTView *)createLTViewWithFrame:(CGRect )frame

                    andLabelTitle:(NSString *)labelTitle

                    andPlacehodle:(NSString *)placehodle

{

    

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

    

    [ltView giveLabelText:labelTitle];

    

    [ltView giveTextFieldPlaceholder:placehodle];

    

    return  [ltView autorelease];

    

}


- (void)dealloc

{

    [_userName release];

    [_password release];

    [_confirmPassword release];

    [_telephone release];

    [_email release];

    [_confirmButton release];

    [_cancelButton release];

    [super dealloc];

}



/*

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

{

    [super loadView];

    

    self.findPwdView = [[FindPwdView alloc] initWithFrame:[UIScreen mainScreen].bounds];

    

    self.view = self.findPwdView;

    

    [self.findPwdView release];

    

}


- (void)viewDidLoad {

    [super viewDidLoad];

    

    //点击按钮响应事件

    //确定

    [self.findPwdView.confirmButton addTarget:self action:@selector(certainButtonAction:) forControlEvents:UIControlEventTouchUpInside];


    //取消

    [self.findPwdView.cancelButton addTarget:self action:@selector(cancelButtonAction:) forControlEvents:UIControlEventTouchUpInside];

    

    //注册

    [self.findPwdView.registerButton addTarget:self action:@selector(registerButtonAction:) forControlEvents:UIControlEventTouchUpInside];

    

    

    //登陆

    

    [self.findPwdView.loginButton addTarget:self action:@selector(loginButtonAction:) forControlEvents:UIControlEventTouchUpInside];

    

}


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

- (void)certainButtonAction:(UIButton *)sender

{

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

    

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

    if ([self.findPwdView.userName getTextField].length == 0 || [self.findPwdView.telePhone getTextField] == 0) {

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

        [view show];

        [view release];

    } else {

        //验证成功

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

        

        

        

        [view show];

        [view release];

    }

}


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

- (void)cancelButtonAction:(UIButton *)sender

{

    [self dismissViewControllerAnimated:YES completion:nil];

}


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

- (void)loginButtonAction:(UIButton *)sender

{

    [self dismissViewControllerAnimated:YES completion:nil];

    

}


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


- (void)registerButtonAction:(UIButton *)sender

{

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

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

    

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

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

    

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

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

        self.view = nil;

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

    }


    // Dispose of any resources that can be recreated.

}


- (void)dealloc

{

    

    [_findPwdView release];

    [super dealloc];

}


/*

#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 = [super initWithFrame:frame];

    if (self) {

        

        [self addSubviews];

    }

    return self;

}

#pragma mark - 添加控件

- (void)addSubviews

{

    

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

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

    [self addSubview:self.userName];

    

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

    self.telePhone.textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

    [self addSubview:self.telePhone];

    

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

    [self addSubview:self.email];

    

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

    [self addSubview:self.confirmButton];

    

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

    [self addSubview:self.cancelButton];

    

    

}

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

- (UIButton *)createButtonWithFrame:(CGRect )frame

                      andTitleLabel:(NSString *)titleLabel

{

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

    

    button.frame = frame;

    

    [button setTitle:titleLabel forState:UIControlStateNormal];

    

    return button ;

}

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

- (LTView *)createLTViewWithFrame:(CGRect )frame

                    andLabelTitle:(NSString *)labelTitle

                    andPlacehodle:(NSString *)placehodle

{

    

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

    

    [ltView giveLabelText:labelTitle];

    

    [ltView giveTextFieldPlaceholder:placehodle];

    

    return  [ltView autorelease];

    

}


- (void)dealloc

{

    [_userName release];

    [_telePhone release];

    [_email release];

    [_confirmButton release];

    [_cancelButton release];

    [super dealloc];

}



/*

// 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 = [super initWithFrame:frame];

    if (self) {

        //添加label

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

        self.label.backgroundColor = [UIColor whiteColor];

        [self addSubview:self.label];

        [self.label release];

        

        //添加textField

        //输入框

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

        self.textField.backgroundColor = [UIColor lightTextColor];

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

        self.textField.borderStyle = UITextBorderStyleRoundedRect;

        self.textField.layer.borderWidth = 1;

        self.textField.layer.borderColor = [[UIColor blueColor]CGColor];

        self.textField.layer.cornerRadius = 10;

        //输入框的清空设置

        self.textField.clearsOnBeginEditing = YES;

        self.textField.clearButtonMode = UITextFieldViewModeAlways;

        //改变键盘的return的类型

        self.textField.keyboardType = UIReturnKeyNext;

        

        [self addSubview:self.textField];

        [self.textField release];

        

    }

    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.textField resignFirstResponder];

    

}

//给外界提供改变内部两个控件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

{

    [_label release];

    [_textField release];

    

    [super dealloc];

}


@end



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值