简单的视图切换(tag)

6 篇文章 0 订阅

#import "AppDelegate.h"

@interface AppDelegate ()
{
    UIWindow *_window;

    //    pwdText.tag = 103;
}

@end

@implementation AppDelegate


- (void)dealloc
{
    [_window release];
    [super dealloc];
}

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


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

    //创建登陆视图

    UIView *loginView = [[UIView alloc]initWithFrame:_window.frame];
    loginView.tag = 101;
//    [_window addSubview:loginView];

    loginView.backgroundColor = [UIColor yellowColor];


    //用户名
    UILabel *userName = [[UILabel alloc]initWithFrame:CGRectMake(20, 50, 70, 30)];
    userName.text = @"用户名";


    UITextField *name = [[UITextField alloc]initWithFrame:CGRectMake(130, 50, 150, 30)];
    name.borderStyle = UITextBorderStyleRoundedRect;
    name.placeholder = @"请输入姓名";
    name.keyboardType = UIKeyboardTypeNumberPad;




    //密码
    UILabel *pwd = [[UILabel alloc]initWithFrame:CGRectMake(20, 100, 70, 30)];
    pwd.text = @"密码";


    UITextField *pwdText = [[UITextField alloc]initWithFrame:CGRectMake(130, 100, 150, 30)];
    pwdText.borderStyle = UITextBorderStyleRoundedRect;

    pwdText.keyboardType = UIKeyboardTypeNumberPad;
    pwdText.tag = 103;
    pwdText.placeholder = @"请输入密码";




    //登陆按钮

    UIButton *loginButton  = [UIButton buttonWithType:UIButtonTypeCustom ];

    [loginButton setTitle:@"登陆" forState:UIControlStateNormal];
    loginButton.backgroundColor = [UIColor greenColor];
    loginButton.frame = CGRectMake(50, 200, 60, 30);

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


    //找回密码


    UIButton *findButton  = [UIButton buttonWithType:UIButtonTypeCustom ];

    [findButton setTitle:@"找回密码" forState:UIControlStateNormal];
    findButton.backgroundColor  = [UIColor greenColor];
    findButton.frame = CGRectMake(150, 200, 100, 30);

    [findButton addTarget:self action:@selector(findpwd) forControlEvents:UIControlEventTouchUpInside];




    [loginView addSubview:name];
    [loginView addSubview:userName ];
    [loginView addSubview:loginButton];
    [loginView addSubview:findButton];
    [loginView addSubview:pwdText];
    [loginView addSubview:pwd ];



    [pwd release];
    [pwdText release];
    [name release];
    [userName release];

    //创建找回密码视图

    UIView *findPwdView = [[UIView alloc]initWithFrame:_window.frame];
    findPwdView.tag = 102;
    findPwdView.backgroundColor = [UIColor orangeColor];



    UILabel *emailLable = [[UILabel alloc]initWithFrame:CGRectMake(20, 50, 70, 30)];
    emailLable.text = @"邮箱";


    UITextField *emailTF = [[UITextField alloc]initWithFrame:CGRectMake(130, 50, 150, 30)];
    emailTF.borderStyle = UITextBorderStyleRoundedRect;
    emailTF.placeholder = @"请输入邮箱";


    //取消按钮

    UIButton *concelButton  = [UIButton buttonWithType:UIButtonTypeCustom ];

    [concelButton setTitle:@"取消" forState:UIControlStateNormal];
    concelButton.frame = CGRectMake(100, 200, 60, 30);

    [concelButton addTarget:self action:@selector(concel) forControlEvents:UIControlEventTouchUpInside];


    //添加视图
    [findPwdView addSubview:emailLable];
    [findPwdView addSubview:emailTF];


    [findPwdView addSubview:concelButton];


    [emailTF release];
    [emailLable release];





    //将两个视图添加到_window上

    [_window addSubview:findPwdView];
    [_window addSubview:loginView];


    [findPwdView release];
    [loginView release];





    [_window makeKeyAndVisible];

    return YES;
}

-(void)concel{

    [_window bringSubviewToFront:[_window viewWithTag:101]];
}
-(void)login{


    UITextField *passwordTF =(UITextField *)[[_window viewWithTag:101] viewWithTag:103];
    if ([passwordTF.text isEqualToString:@"123"]) {
        UIAlertView *alertView =[[UIAlertView alloc]initWithTitle:@"提示" message:@"欢迎回来" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alertView show];
        [alertView release];
    }else{
        UIAlertView *alertView =[[UIAlertView alloc]initWithTitle:@"提示" message:@"密码错误" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alertView show];
        [alertView release];
    }

}

-(void)findpwd{
    [_window bringSubviewToFront:[_window viewWithTag:102]];
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值