用IOS做一个界面切换的效果(登录界面和注册界面和找回密码界面的切换)(用封装好的lable和textf创建界面)

创建一个类封装uitextfield和UIlabel (源代码.m文件)

#import "TLView.h"

@interface TLView ()

{

    UILabel *_desLabel;    //左边的lable

    UITextField *_textField;//右边的

}

@end

@implementation TLView



//改写父类的初始化方法,处理相同的性能

- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        // Initialization code

        CGFloat width = frame.size.width;

        CGFloat height = frame.size.height;

        //UIlabel

        _desLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0.3 * width, height)];

        _desLabel.font = [UIFont systemFontOfSize:18];

        _desLabel.textAlignment = NSTextAlignmentRight;

        //        _desLabel.backgroundColor = [UIColor lightGrayColor];

        [self addSubview:_desLabel];

        [_desLabel release];

        

        //UITextfield

        _textField = [[UITextField alloc] initWithFrame:CGRectMake(0.4 * width, 0 , 0.6 * width , height)];

        _textField.borderStyle = UITextBorderStyleRoundedRect;

        //        _textField.backgroundColor = [UIColor lightGrayColor];

        _textField.autocorrectionType = UITextAutocorrectionTypeNo;

        [self addSubview:_textField];

        [_textField release];


    }

    return self;

}

//改写初始化方法,处理不同的部分

- (id)initWithFrame:(CGRect)frame labelText:(NSString *)labelText placeholder:(NSString *)placeholder textFieldText:(NSString *)textFieldText{

    self = [self initWithFrame:frame];

    if (self) {

        //initialization code here..

        _desLabel.text = labelText;        //

        _textField.placeholder = placeholder;

        _textField.text = textFieldText;

        

    }

    return self;

}



//填写各种方法,处理不同的部分

//1,是否采用安全模式

- (void)setSecureEntry:(BOOL)secureEntry{

    _textField.secureTextEntry = secureEntry;

}

//2,设置键盘类型;

- (void)setKeyBoardType:(UIKeyboardType)keyBoardType{

    _textField.keyboardType = keyBoardType;

}

//3,设置textField代理

- (void)setDelegate:(id<UITextFieldDelegate>)delegate{

    _textField.delegate = delegate;

}

//4,获取输入框中的文字

- (NSString *)text{

    return _textField.text;

}


@end




源代码(.m文件)

#import "ZKJAppDelegate.h"

#import "TLView.h"

#define main_tag 1000;

#define youxiang_tag 1002;

#define zhuce_tag 1001;

@interface ZKJAppDelegate ()

{

    UIView *mainView;

    UIView *_loginView;

    UIView *_registerView;

    UIView *_huntforView;

}

@end




@implementation ZKJAppDelegate


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

{

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Override point for customization after application launch.


    

    mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];

    mainView.backgroundColor = [UIColor lightGrayColor];

    /**

     *  ///

     */

    //第三张视图  找回密码

    

    _huntforView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)];

    _huntforView.backgroundColor = [UIColor whiteColor];

    [mainView addSubview:_huntforView];

    [_huntforView release];

    

    UITextField *emailTextField = [[UITextField alloc] initWithFrame:CGRectMake(50, 100, 200, 30)];

    emailTextField.placeholder = @"邮箱";

    emailTextField.borderStyle = UITextBorderStyleRoundedRect;

    emailTextField.autocorrectionType = UITextAutocorrectionTypeNo;

    emailTextField.delegate = self;

    [_huntforView addSubview:emailTextField];

    [emailTextField release];

    [self creatButton2];

    

    

    

    //第二张视图  注册视图

    _registerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];

    _registerView.backgroundColor = [UIColor whiteColor];

    [mainView addSubview:_registerView];

    [_registerView release];

    

    NSArray *lableTexts1 = @[@"用户:",@"密码:",@"确认密码:",@"手机号:",@"邮箱:",@"住址:"];

    NSArray *placeholders1 = @[@"请输入用户:",@"请输入密码:",@"请输入确认密码:",@"请输入手机号:",@"请输入邮箱:",@"请输入住址:"];

    NSInteger y1 = 50;

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

        TLView *ltView = [[TLView alloc]initWithFrame:CGRectMake(30, 50 * i + y1 , 260, 30) labelText: lableTexts1[i] placeholder:placeholders1[i] textFieldText:nil];

        [ltView setDelegate:self];

        if (i == 1 || i == 2) {

            //设置安全模式

            [ltView setSecureEntry:YES];

        }

        if (i ==3) {

            [ltView setKeyBoardType:UIKeyboardTypeNumberPad];

        }

        ltView.tag = 100 + i;

        [_registerView addSubview: ltView];

    }

    [self creatButton1];


    //第一张视图 登录界面

    _loginView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];

    _loginView.backgroundColor = [UIColor lightGrayColor];

    _loginView.tag = main_tag;

    [mainView addSubview:_loginView];

    [_loginView release];

    

    

    NSArray *lableTexts = @[@"用户:",@"密码:",@"确认密码:",@"手机号:",@"邮箱:",@"住址:"];

    NSArray *placeholders = @[@"请输入用户:",@"请输入密码:",@"请输入确认密码:",@"请输入手机号:",@"请输入邮箱:",@"请输入住址:"];

    NSInteger y = 50;

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

        TLView *ltView = [[TLView alloc]initWithFrame:CGRectMake(30, 50 * i + y , 260, 30) labelText: lableTexts[i] placeholder:placeholders[i] textFieldText:nil];

        [ltView setDelegate:self];

        if (i == 1 || i == 2) {

            //设置安全模式

            [ltView setSecureEntry:YES];

        }

        if (i ==3) {

            [ltView setKeyBoardType:UIKeyboardTypeNumberPad];

        }

        ltView.tag = 100 + i;

        [_loginView addSubview: ltView];

    }

    [self creatButton];

    

    /**

     *  ///

     */

    [self.window addSubview:mainView];

    [mainView release];

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    return YES;

}

/**

 *  /

 */

- (void)creatButton{

    UIButton *regisButton = [UIButton buttonWithType:UIButtonTypeSystem];

    regisButton.frame = CGRectMake(50, 400, 220, 40);

    [regisButton setTitle:@"注册" forState:UIControlStateNormal];

    regisButton.backgroundColor = [UIColor lightGrayColor];

    [regisButton addTarget:self action:@selector(registerClick) forControlEvents:UIControlEventTouchUpInside];

    [_loginView addSubview: regisButton];

    //    [regisButton release];

    

    UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeSystem];

    loginButton.frame = CGRectMake(50, 300, 220, 40);

    [loginButton addTarget:self action:@selector(loginClick) forControlEvents:UIControlEventTouchUpInside];

    [loginButton setTitle:@"登录" forState:UIControlStateNormal];

    [loginButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    loginButton.backgroundColor = [UIColor redColor];

    

    loginButton.layer.cornerRadius = 5;

    [_loginView addSubview:loginButton];

    //    [cancleButton release];

    

    UIButton *huntButton = [UIButton buttonWithType:UIButtonTypeSystem];

    huntButton.frame = CGRectMake(50, 200, 220, 40);

    [huntButton addTarget:self action:@selector(huntForClick) forControlEvents:UIControlEventTouchUpInside];

    [huntButton setTitle:@"找回密码" forState:UIControlStateNormal];

    [huntButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    huntButton.backgroundColor = [UIColor lightGrayColor];

    

    huntButton.layer.cornerRadius = 5;

    [_loginView addSubview:huntButton];

    

    

}


/**

 *  //

 *

 *  @param application ;

 */


- (void)creatButton1{

    UIButton *regisButton = [UIButton buttonWithType:UIButtonTypeSystem];

    regisButton.frame = CGRectMake(50, 400, 220, 40);

    [regisButton setTitle:@"注册" forState:UIControlStateNormal];

    regisButton.backgroundColor = [UIColor lightGrayColor];

    [regisButton addTarget:self action:@selector(registerClick1) forControlEvents:UIControlEventTouchUpInside];

    [_registerView addSubview: regisButton];

    //    [regisButton release];

    

    UIButton *cancleButton = [UIButton buttonWithType:UIButtonTypeSystem];

    cancleButton.frame = CGRectMake(50, 300, 220, 40);

    [cancleButton addTarget:self action:@selector(cancelClick1) forControlEvents:UIControlEventTouchUpInside];

    [cancleButton setTitle:@"取消" forState:UIControlStateNormal];

    [cancleButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    cancleButton.backgroundColor = [UIColor lightGrayColor];

    

    cancleButton.layer.cornerRadius = 5;

    [_registerView addSubview:cancleButton];

    //    [cancleButton release];

}


/**

 * 

 */

- (void)creatButton2{

    UIButton *regisButton = [UIButton buttonWithType:UIButtonTypeSystem];

    regisButton.frame = CGRectMake(50, 400, 220, 40);

    [regisButton setTitle:@"找回" forState:UIControlStateNormal];

    regisButton.backgroundColor = [UIColor lightGrayColor];

    [regisButton addTarget:self action:@selector(zhaoHui2) forControlEvents:UIControlEventTouchUpInside];

    [_huntforView addSubview: regisButton];

    //    [regisButton release];

    

    UIButton *cancleButton = [UIButton buttonWithType:UIButtonTypeSystem];

    cancleButton.frame = CGRectMake(50, 300, 220, 40);

    [cancleButton addTarget:self action:@selector(quXiao2) forControlEvents:UIControlEventTouchUpInside];

    [cancleButton setTitle:@"取消" forState:UIControlStateNormal];

    [cancleButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    cancleButton.backgroundColor = [UIColor lightGrayColor];

    

    cancleButton.layer.cornerRadius = 5;

    [_huntforView addSubview:cancleButton];

    //    [cancleButton release];

}

//       //00000000000

- (void)loginClick{      //登录

    NSLog(@"正在登录...");

}

- (void)huntForClick{   //找回密码

   

   

    NSLog(@"找回密码");

    [mainView exchangeSubviewAtIndex:2 withSubviewAtIndex:0];

    

}

- (void)registerClick{   //注册

    [mainView exchangeSubviewAtIndex:2 withSubviewAtIndex:1];

    NSLog(@"注册");

    

//    [mainView exchangeSubviewAtIndex:2  withSubviewAtIndex:1];

    

}

//      //    1111111111

- (void)registerClick1{  // 注册

    

}

- (void)cancelClick1{    //取消

    [mainView exchangeSubviewAtIndex:2 withSubviewAtIndex:1];

    

}

//        //       22222222222

- (void)zhaoHui2{  //找回

    

}

- (void)quXiao2{   //取消

    [mainView exchangeSubviewAtIndex:0 withSubviewAtIndex:2];

}





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

}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{

    [textField resignFirstResponder];

    return YES;

}

- (void)dealloc{

    NSLog(@"释放内存");

    [self.window release];

    [super dealloc];

    

}

@end



  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值