#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]];
}
简单的视图切换(tag)
最新推荐文章于 2022-10-28 11:28:19 发布