UI入门——简单登陆界面,注册界面及找回密码界面铺设以及切换
来源:互联网 发布:php模板引擎与java 编辑:程序博客网 时间:2024/06/10 14:59
AppDelegate.h
<pre name="code" class="objc"><span style="font-size: 18px;">#import <UIKit/UIKit.h>@interface AppDelegate : UIResponder <UIApplicationDelegate, UITextFieldDelegate, UIAlertViewDelegate></span>
<span style="font-size: 18px;">@property (retain, nonatomic) UIWindow *window;</span>
<span style="font-size: 18px;">@end</span>
AppDelegate.m
<span style="font-size:18px;">@interface AppDelegate ()// 设置属性为了alert@property (retain, nonatomic) UITextField *greenView2;@property (retain, nonatomic) UITextField *blueView2;@property (retain, nonatomic) UIButton *redView1;@property (retain, nonatomic) UIView *loginContainerView;@property (retain, nonatomic) UIView *registContainerView;@property (retain, nonatomic) UIView *passwordContainerView;@property (retain, nonatomic) UITextField *nameImport;@property (retain, nonatomic) UITextField *passwordImport;@property (retain, nonatomic) UITextField *passwordImportAgain;@end@implementation AppDelegate- (void)dealloc{ [_window release]; [super dealloc];}// 回收键盘- (BOOL)textFieldShouldReturn:(UITextField *)textField{ [textField resignFirstResponder]; return YES;}// 添加alert// 1.登陆界面- (void)alertViewShow1{ NSLog(@"greenView2 %@ blueView2 %@", self.greenView2.text, self.blueView2.text); if ([self.greenView2.text isEqualToString:@"我"] && [self.blueView2.text isEqualToString:@"123"]) { UIAlertView *alertView1 = [[UIAlertView alloc] initWithTitle:@"提示" message:@"欢迎回来" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; [alertView1 show]; [alertView1 release]; } else { UIAlertView *alertView2 = [[UIAlertView alloc] initWithTitle:@"提示" message:@"用户名或者密码错误,请核对后再试" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; [alertView2 show]; [alertView2 release]; }}// 2.注册界面- (void)alertViewShow2{ if ([self.passwordImport.text isEqualToString:self.passwordImportAgain.text] && self.nameImport.text.length != 0 && self.passwordImport.text.length != 0 && self.passwordImportAgain.text.length != 0) { UIAlertView *alertView3 = [[UIAlertView alloc] initWithTitle:@"注册成功" message:@"大家庭欢饮您" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; [alertView3 show]; [alertView3 release]; } else if (self.nameImport.text.length == 0 || self.passwordImport.text.length == 0 || self.passwordImportAgain.text.length == 0) { UIAlertView *alertView4 = [[UIAlertView alloc] initWithTitle:@"注册失败" message:@"用户名密码或确认密码不能为空" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; [alertView4 show]; [alertView4 release]; } else if (![self.passwordImport.text isEqualToString:self.passwordImportAgain.text]) { UIAlertView *alertView5 = [[UIAlertView alloc] initWithTitle:@"注册失败" message:@"两次密码输入不一致" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; [alertView5 show]; [alertView5 release]; }}// 注册界面// 高级键盘回收//- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{// [self.window endEditing:YES];//}////- (void)downKeyBoard:(UITextField *)textField//{// [textField resignFirstResponder];//}// 切换界面- (void)toPasswordFind{ [self.window insertSubview:self.passwordContainerView atIndex:3];}- (void)toRegister{ [self.window insertSubview:self.registContainerView atIndex:3];}- (void)toLogin{ [self.window insertSubview:self.loginContainerView atIndex:3];}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; // 登陆界面 self.loginContainerView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.loginContainerView.backgroundColor = [UIColor whiteColor]; [self.window addSubview:self.loginContainerView]; UILabel *greenView1 = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 80, 30)]; greenView1.text = @"用户名"; [self.loginContainerView addSubview:greenView1]; self.greenView2 = [[UITextField alloc] initWithFrame:CGRectMake(150, 100, 150, 30)]; self.greenView2.placeholder = @"手机号/邮箱"; self.greenView2.textAlignment = NSTextAlignmentCenter; self.greenView2.borderStyle = UITextBorderStyleRoundedRect; self.greenView2.delegate = self; self.greenView2.clearButtonMode = UITextFieldViewModeWhileEditing; [self.loginContainerView addSubview:self.greenView2]; UILabel *blueView1 = [[UILabel alloc] initWithFrame:CGRectMake(50, 150, 80, 30)]; blueView1.text = @"密码"; [self.loginContainerView addSubview:blueView1]; self.blueView2 = [[UITextField alloc] initWithFrame:CGRectMake(150, 150, 150, 30)]; self.blueView2.placeholder = @"请输入密码"; self.blueView2.textAlignment = NSTextAlignmentCenter; self.blueView2.borderStyle = UITextBorderStyleRoundedRect; self.blueView2.secureTextEntry = YES; self.blueView2.delegate = self; self.blueView2.clearButtonMode = UITextFieldViewModeWhileEditing; [self.loginContainerView addSubview:self.blueView2]; UIButton *redView1 = [[UIButton alloc] initWithFrame:CGRectMake(40, 210, 70, 30)]; [redView1 setTitle:@"登陆" forState:UIControlStateNormal]; [redView1 setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; [redView1 setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted]; // 添加alert [redView1 addTarget:self action:@selector(alertViewShow1) forControlEvents:UIControlEventTouchUpInside]; [self.loginContainerView addSubview:redView1]; UIButton *redView2 = [[UIButton alloc] initWithFrame:CGRectMake(130, 210, 80, 30)]; [redView2 setTitle:@"找回密码" forState:UIControlStateNormal]; [redView2 setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; [redView2 setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted]; [self.loginContainerView addSubview:redView2]; UIButton *redView3 = [[UIButton alloc] initWithFrame:CGRectMake(230, 210, 70, 30)]; [redView3 setTitle:@"注册" forState:UIControlStateNormal]; [redView3 setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; [redView3 setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted]; [self.loginContainerView addSubview:redView3]; // 找回密码界面 self.passwordContainerView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.passwordContainerView.backgroundColor = [UIColor whiteColor]; [self.window addSubview:self.passwordContainerView]; UITextField *passwordFind = [[UITextField alloc] initWithFrame:CGRectMake(80, 150, 220, 30)]; passwordFind.borderStyle = UITextBorderStyleRoundedRect; passwordFind.placeholder = @"电子邮箱"; passwordFind.delegate = self; passwordFind.clearButtonMode = UITextFieldViewModeWhileEditing; [self.passwordContainerView addSubview:passwordFind]; UIButton *passwordFindYes = [[UIButton alloc] initWithFrame:CGRectMake(100, 200, 80, 20)]; [passwordFindYes setTitle:@"找回" forState:UIControlStateNormal]; [passwordFindYes setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; [passwordFindYes setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted]; [self.passwordContainerView addSubview:passwordFindYes]; UIButton *passwordFindNo = [[UIButton alloc] initWithFrame:CGRectMake(200, 200, 80, 20)]; [passwordFindNo setTitle:@"取消" forState:UIControlStateNormal]; [passwordFindNo setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; [passwordFindNo setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted]; [self.passwordContainerView addSubview:passwordFindNo]; // 注册界面 // 覆盖window self.registContainerView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.registContainerView.backgroundColor = [UIColor whiteColor]; [self.window addSubview:self.registContainerView]; // 用户名 UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 100, 25)]; name.text = @"用户名"; [self.registContainerView addSubview:name]; self.nameImport = [[UITextField alloc] initWithFrame:CGRectMake(150, 100, 200, 25)];// [self.nameImport setReturnKeyType:UIReturnKeyDone];// [self.nameImport addTarget:self action:@selector(downKeyBoard:) forControlEvents:UIControlEventEditingDidEndOnExit]; self.nameImport.delegate = self; self.nameImport.placeholder = @"请输入用户名"; self.nameImport.clearButtonMode = UITextFieldViewModeWhileEditing; self.nameImport.borderStyle = UITextBorderStyleRoundedRect; self.nameImport.alpha = 0.8; [self.registContainerView addSubview:self.nameImport]; // 密码 UILabel *password = [[UILabel alloc] initWithFrame:CGRectMake(50, 150, 100, 25)]; password.text = @"密码"; [self.registContainerView addSubview:password]; self.passwordImport = [[UITextField alloc] initWithFrame:CGRectMake(150, 150, 200, 25)];// [self.passwordImport setReturnKeyType:UIReturnKeyDone];// [self.passwordImport addTarget:self action:@selector(downKeyBoard:) forControlEvents:UIControlEventEditingDidEndOnExit]; self.passwordImport.delegate = self; self.passwordImport.placeholder = @"请输入密码"; self.passwordImport.clearButtonMode = UITextFieldViewModeWhileEditing; self.passwordImport.secureTextEntry = YES; self.passwordImport.borderStyle = UITextBorderStyleRoundedRect; self.passwordImport.alpha = 0.8; [self.registContainerView addSubview:self.passwordImport]; // 确认密码 UILabel *passwordEnsure = [[UILabel alloc] initWithFrame:CGRectMake(50, 200, 100, 25)]; passwordEnsure.text = @"确认密码"; [self.registContainerView addSubview:passwordEnsure]; self.passwordImportAgain = [[UITextField alloc] initWithFrame:CGRectMake(150, 200, 200, 25)];// [self.passwordImportAgain setReturnKeyType:UIReturnKeyDone];// [self.passwordImportAgain addTarget:self action:@selector(downKeyBoard:) forControlEvents:UIControlEventEditingDidEndOnExit]; self.passwordImportAgain.delegate = self; self.passwordImportAgain.placeholder = @"再次输入密码"; self.passwordImportAgain.clearButtonMode = UITextFieldViewModeWhileEditing; self.passwordImportAgain.secureTextEntry = YES; self.passwordImportAgain.borderStyle = UITextBorderStyleRoundedRect; self.passwordImportAgain.alpha = 0.8; [self.registContainerView addSubview:self.passwordImportAgain]; // 手机号 UILabel *phone = [[UILabel alloc] initWithFrame:CGRectMake(50, 250, 100, 25)]; phone.text = @"手机号"; [self.registContainerView addSubview:phone]; UITextField *phoneImport = [[UITextField alloc] initWithFrame:CGRectMake(150, 250, 200, 25)];// [phoneImport setReturnKeyType:UIReturnKeyDone];// [phoneImport addTarget:self action:@selector(downKeyBoard:) forControlEvents:UIControlEventEditingDidEndOnExit]; phoneImport.delegate = self; phoneImport.placeholder = @"请输入联系方式"; phoneImport.clearButtonMode = UITextFieldViewModeWhileEditing; phoneImport.borderStyle = UITextBorderStyleRoundedRect; phoneImport.keyboardType = UIKeyboardTypeNumberPad; phoneImport.alpha = 0.8; [self.registContainerView addSubview:phoneImport]; // 邮箱 UILabel *mail = [[UILabel alloc] initWithFrame:CGRectMake(50, 300, 100, 25)]; mail.text = @"邮箱"; [self.registContainerView addSubview:mail]; UITextField *mailImport = [[UITextField alloc] initWithFrame:CGRectMake(150, 300, 200, 25)];// [mailImport setReturnKeyType:UIReturnKeyDone];// [mailImport addTarget:self action:@selector(downKeyBoard:) forControlEvents:UIControlEventEditingDidEndOnExit]; mailImport.delegate = self; mailImport.placeholder = @"请输入邮箱"; mailImport.clearButtonMode = UITextFieldViewModeWhileEditing; mailImport.borderStyle = UITextBorderStyleRoundedRect; mailImport.alpha = 0.8; [self.registContainerView addSubview:mailImport]; // 注册 取消 UIButton *_register = [[UIButton alloc] initWithFrame:CGRectMake(40, 400, 150, 25)]; [_register setTitle:@"注册" forState:UIControlStateNormal] ; [_register setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; [_register setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted]; [self.registContainerView addSubview:_register]; // 添加alert [_register addTarget:self action:@selector(alertViewShow2) forControlEvents:UIControlEventTouchUpInside]; UIButton *cancel = [[UIButton alloc] initWithFrame:CGRectMake(190, 400, 150, 25)]; [cancel setTitle:@"取消" forState:UIControlStateNormal]; [cancel setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; [cancel setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted]; [self.registContainerView addSubview:cancel]; // 切换界面 [self.window insertSubview:self.loginContainerView atIndex:3]; // 登陆界面切换到其他界面 [redView2 addTarget:self action:@selector(toPasswordFind) forControlEvents:UIControlEventTouchUpInside]; [redView3 addTarget:self action:@selector(toRegister) forControlEvents:UIControlEventTouchUpInside]; // 找回界面切换到登陆界面 [passwordFindNo addTarget:self action:@selector(toLogin) forControlEvents:UIControlEventTouchUpInside]; // 注册界面切换到登陆界面 [cancel addTarget:self action:@selector(toLogin) forControlEvents:UIControlEventTouchUpInside]; // 释放 // 登陆界面释放 [self.loginContainerView release]; [greenView1 release]; [self.greenView2 release]; [blueView1 release]; [self.blueView2 release]; [redView1 release]; [redView2 release]; [redView3 release]; // 找回密码界面 [self.passwordContainerView release]; [passwordFind release]; [passwordFindYes release]; [passwordFindNo release]; // 注册界面释放 [self.registContainerView release]; [name release]; [self.nameImport release]; [password release]; [self.passwordImport release]; [passwordEnsure release]; [self.passwordImportAgain release]; [phone release]; [phoneImport release]; [mail release]; [mailImport release]; [_register release]; [cancel release]; 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</span>
0 0
- UI入门——简单登陆界面,注册界面及找回密码界面铺设以及切换
- JSP登陆界面的找回密码功能
- 用IOS做一个界面切换的效果(登录界面和注册界面和找回密码界面的切换)(用封装好的lable和textf创建界面)
- iOS登陆界面切换到注册界面并返回的UI设计(简易向)
- c#web窗体登录界面登录注册以及密码找回发送邮箱功能
- QT登陆注册界面
- 模拟登陆注册界面
- Android设计登录界面、找回密码、注册功能
- ubuntu 切换登陆界面
- UI简易登陆界面
- 登陆界面记住密码
- 拼成一个找回密码界面
- C#-—登陆界面
- unity 简单登陆界面 ——PlayerPrefs
- java 简单界面登陆
- ExtJS简单登陆界面
- 简单html登陆界面
- easyui简单登陆界面
- 博弈之 Nim 游戏和 sg 函数
- 写 游戏后台管理系统时 碰到的问题 导航页面怎么编写的问题
- 深入理解JavaScript系列(25):设计模式之单例模式
- GCC在C语言中内嵌汇编 asm __volatile__
- 初识Cocos2D-X
- UI入门——简单登陆界面,注册界面及找回密码界面铺设以及切换
- 【c++版数据结构】之双链表的实现(带头结点以及尾节点)
- leetcode-124:Binary Tree Maximum Path Sum(Java)
- 深入理解JavaScript系列(26):设计模式之构造函数模式
- light oj 1317
- ACM大一练习赛-第三场------G - EPR悖论<克鲁斯卡尔算法>
- linux内核转储的设置、调试
- Convert QWERTY to Dvorak ZOJ 3878
- 最长连续三字符子串问题