新建一個(gè)工程,實(shí)現(xiàn)登陸系統(tǒng),即登陸頁面、注冊頁面、找回密碼頁面之間的切換。
創(chuàng)新互聯(lián)建站自2013年起,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站建設(shè)、網(wǎng)站制作網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢想脫穎而出為使命,1280元深州做網(wǎng)站,已為上家服務(wù),為深州各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:028-869222201、創(chuàng)建視圖對象loginContainerView(登陸頁面),registContainerView(注冊頁面),passwordContainerView(找回密碼頁面),將3個(gè)視圖作為window的子視圖。默認(rèn)顯示登陸頁面。
2、點(diǎn)擊登陸頁面的登陸按鈕,驗(yàn)證是否登陸成功。
3、點(diǎn)擊登陸頁面的找回密碼按鈕,切換顯示找回密碼頁面。
4、點(diǎn)擊登陸頁面的注冊按鈕,切換顯示注冊頁面。
5、點(diǎn)擊找回密碼頁面的取消按鈕,切換返回登陸頁面。
6、點(diǎn)擊注冊頁面的取消按鈕,卻換返回登陸頁面。
#import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate - (void)dealloc { [_window release]; [super dealloc]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. self.window = [[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]]autorelease]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; //創(chuàng)建注冊頁面 [self creatRegisterView]; //創(chuàng)建找回密碼頁面 [self creatFindPassView]; //創(chuàng)建登陸頁面 [self creatLoginView]; return YES; } - (void)creatLoginView { //登陸頁面 UIView *loginView = [[UIView alloc]initWithFrame:_window.frame]; loginView.tag = 1000; loginView.backgroundColor = [UIColor whiteColor]; [self.window addSubview:loginView]; [loginView release]; //用戶名label UILabel *userNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 100, 80, 30)]; userNameLabel.text = @"用戶名"; userNameLabel.backgroundColor = [UIColor whiteColor]; [loginView addSubview:userNameLabel]; [userNameLabel release]; //密碼label UILabel *passLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 150, 80, 30)]; passLabel.text = @"密碼"; passLabel.backgroundColor = [UIColor whiteColor]; [loginView addSubview:passLabel]; [passLabel release]; //用戶名textField UITextField *userNameTF = [[UITextField alloc]initWithFrame:CGRectMake(130, 100, 200, 30)]; userNameTF.tag = 1001; userNameTF.placeholder = @"請輸入用戶名"; userNameTF.clearButtonMode = UITextFieldViewModeAlways; userNameTF.borderStyle = UITextBorderStyleRoundedRect; [loginView addSubview:userNameTF]; userNameTF.keyboardType = UIKeyboardTypeDefault;//鍵盤類型 userNameTF.returnKeyType = UIReturnKeyDone; //設(shè)置代理 userNameTF.delegate = self; [userNameTF release]; //密碼textField UITextField *passTF = [[UITextField alloc]initWithFrame:CGRectMake(130, 150, 200, 30)]; passTF.tag = 1002; passTF.placeholder = @"請輸入密碼"; passTF.secureTextEntry = YES; passTF.clearButtonMode = UITextFieldViewModeAlways; passTF.borderStyle = UITextBorderStyleRoundedRect; [loginView addSubview:passTF]; passTF.delegate = self;//代理 [passTF release]; //登陸button UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeSystem]; loginButton.frame = CGRectMake(40, 200, 80, 30); loginButton.backgroundColor = [UIColor whiteColor]; loginButton.titleLabel.font = [UIFont systemFontOfSize:18];//字號 loginButton.backgroundColor = [UIColor whiteColor]; [loginButton setTitle:@"登陸" forState:UIControlStateNormal]; // [loginButton addTarget:self action:@selector(pushLoginView) forControlEvents:UIControlEventTouchUpInside]; [loginButton addTarget:self action:@selector(pushLogin) forControlEvents:UIControlEventTouchUpInside]; [loginView addSubview:loginButton]; //注冊button UIButton *registerButton = [UIButton buttonWithType:UIButtonTypeSystem]; registerButton.frame = CGRectMake(150, 200, 80, 30); registerButton.titleLabel.font = [UIFont systemFontOfSize:18]; registerButton.backgroundColor = [UIColor whiteColor]; [registerButton setTitle:@"注冊" forState:UIControlStateNormal]; [registerButton addTarget:self action:@selector(pushRegister) forControlEvents:UIControlEventTouchUpInside]; [loginView addSubview:registerButton]; //找回密碼button UIButton *findPassButton = [UIButton buttonWithType:UIButtonTypeSystem]; findPassButton.frame = CGRectMake(260, 200, 80, 30); findPassButton.titleLabel.font = [UIFont systemFontOfSize:18]; findPassButton.backgroundColor = [UIColor whiteColor]; [findPassButton setTitle:@"找回密碼" forState:UIControlStateNormal]; [findPassButton addTarget:self action:@selector(pushFindPass) forControlEvents:UIControlEventTouchUpInside]; [loginView addSubview:findPassButton]; } - (void)pushLoginView { //找到登陸界面 UIView *loginView = [_window viewWithTag:1000]; //登陸頁面提前 [_window bringSubviewToFront:loginView]; } - (void)pushRegister { UIView *registerView = [_window viewWithTag:1003]; [_window bringSubviewToFront: registerView]; } - (void)pushFindPass { UIView *findPassView = [_window viewWithTag:1004]; [_window bringSubviewToFront:findPassView]; } - (void)pushLogin { //登陸界面 UIView *loginView = [_window viewWithTag:1000]; //登陸頁面上用戶名輸入框 UITextField *userTextField = (UITextField *)[loginView viewWithTag:1001]; //登陸頁面上的密碼輸入框 UITextField *passTextField = (UITextField *)[loginView viewWithTag:1002]; if (userTextField.text.length == 0) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"用戶名不能為空" delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil]; [alertView show]; [alertView release]; }else if (passTextField.text.length == 0) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示"message:@"密碼不能為空" delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil]; [alertView show]; [alertView release]; }else if ([userTextField.text isEqualToString:@"lanou"] == 1 && [passTextField.text isEqualToString:@"12345"] == 1) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"登陸成功" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil]; [alertView show]; [alertView release]; }else { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"用戶名或者密碼錯誤,請核對后再試" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil]; [alertView show]; [alertView release]; } } - (void)creatRegisterView { //注冊界面 UIView *registerView = [[UIView alloc]initWithFrame:self.window.frame]; registerView.tag = 1003; registerView.backgroundColor = [UIColor whiteColor]; [self.window addSubview:registerView]; [registerView release]; //label的創(chuàng)建 NSArray *array = @[@"用戶名",@"密碼",@"確定密碼",@"電話",@"郵箱",@"地址"]; for (NSInteger i = 0;i < 6;i++) { UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(40, 80+60*i, 90, 40)]; label.text = [NSString stringWithFormat:@"%@:",array[i]]; label.textAlignment = NSTextAlignmentRight; label.font = [UIFont systemFontOfSize:20]; label.backgroundColor = [UIColor whiteColor]; [registerView addSubview:label]; [label release]; //textField的創(chuàng)建 UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(160, 80 +60*i, 160, 40)]; textField.font = [UIFont systemFontOfSize:20]; textField.placeholder = [NSString stringWithFormat:@"請輸入%@",array[i]]; if (i == 2) { textField.placeholder = @"請?jiān)俅屋斎朊艽a"; } textField.backgroundColor = [UIColor whiteColor]; textField.borderStyle = UITextBorderStyleRoundedRect; [registerView addSubview:textField]; textField.delegate = self;//代理 [textField release]; } //注冊button UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeSystem]; loginButton.frame = CGRectMake(70, 500, 100, 30); loginButton.backgroundColor = [UIColor whiteColor]; loginButton.titleLabel.font = [UIFont systemFontOfSize:18]; [loginButton setTitle:@"注冊" forState:UIControlStateNormal]; [registerView addSubview:loginButton]; //取消button UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeSystem]; cancelButton.frame = CGRectMake(200, 500, 100, 30); cancelButton.backgroundColor = [UIColor whiteColor]; cancelButton.titleLabel.font = [UIFont systemFontOfSize:18]; [cancelButton setTitle:@"取消" forState:UIControlStateNormal]; [cancelButton addTarget:self action:@selector(pushLoginView) forControlEvents:UIControlEventTouchUpInside];//跳轉(zhuǎn)頁面 [registerView addSubview:cancelButton]; } - (void)creatFindPassView { //找回密碼界面 UIView *findPassView = [[UIView alloc]initWithFrame:_window.frame]; findPassView.tag = 1004; findPassView.backgroundColor = [UIColor whiteColor]; [_window addSubview:findPassView]; [findPassView release]; //郵箱textfield UITextField *mailTextField = [[UITextField alloc]initWithFrame:CGRectMake(80, 80, 250, 40)]; mailTextField.backgroundColor = [UIColor whiteColor]; mailTextField.font = [UIFont systemFontOfSize:20]; mailTextField.placeholder = @"請輸入電子郵箱"; mailTextField.borderStyle = UITextBorderStyleRoundedRect; [findPassView addSubview:mailTextField]; mailTextField.delegate = self;//代理 [mailTextField release]; //返回Button UIButton *backButton = [UIButton buttonWithType:UIButtonTypeSystem]; backButton.frame = CGRectMake(80, 150, 100, 40); backButton.backgroundColor = [UIColor whiteColor]; backButton.titleLabel.font = [UIFont systemFontOfSize:18]; [backButton setTitle:@"找回" forState:UIControlStateNormal]; [findPassView addSubview:backButton]; //取消button UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeSystem]; cancelButton.frame = CGRectMake(220, 150, 100, 40); cancelButton.backgroundColor = [UIColor whiteColor]; cancelButton.titleLabel.font = [UIFont systemFontOfSize:18]; [cancelButton setTitle:@"取消" forState:UIControlStateNormal]; [cancelButton addTarget:self action:@selector(pushLoginView) forControlEvents:UIControlEventTouchUpInside];//跳轉(zhuǎn)頁面 [findPassView addSubview:cancelButton]; } //收回鍵盤 - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; 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
創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務(wù)器,動態(tài)BGP最優(yōu)骨干路由自動選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機(jī)房獨(dú)有T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確進(jìn)行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動現(xiàn)已開啟,新人活動云服務(wù)器買多久送多久。