QQ登陆注册
2015-12-10 09:47
405 查看
#import "MainViewController.h" #import "CustomView.h" #import "PassViewController.h" #import "RegistViewController.h" @interface MainViewController () @end @implementation MainViewController - (void)dealloc { [super dealloc]; } - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { } return self; } - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; // Do any additional setup after loading the view. [self creatView]; [self CreatButton]; } - (void)creatView { CustomView *userName = [[CustomView alloc] initWithFrame:CGRectMake(30, 150, 280, 40) text:@"用户名"]; [self.view addSubview:userName]; userName.tag = 100; userName.leftText.tag = 1000; [userName release]; CustomView *passWord = [[CustomView alloc] initWithFrame:CGRectMake(30, 200, 280, 40) text:@"密码"]; [self.view addSubview:passWord]; passWord.tag = 10; passWord.leftText.tag = 2000; passWord.leftText.secureTextEntry = YES;//密码模式 [self.view release]; } // 回收键盘 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CustomView *pas = (CustomView *)[self.view viewWithTag:10]; CustomView *name = (CustomView *)[self.view viewWithTag:100]; [pas.leftText resignFirstResponder]; [name.leftText resignFirstResponder]; } - (void)CreatButton { // 登录按钮 UIButton * loginButton = [UIButton buttonWithType:UIButtonTypeCustom]; [loginButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; loginButton.frame = CGRectMake(50, 260, 60, 40); [loginButton setTitle:@"登录" forState:UIControlStateNormal]; [loginButton addTarget:self action:@selector(loginButtonCLicked:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:loginButton]; // 找回密码按钮 UIButton * foundButton = [UIButton buttonWithType:UIButtonTypeCustom]; [foundButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; foundButton.frame = CGRectMake(150, 260, 80, 40); [foundButton setTitle:@"找回密码" forState:UIControlStateNormal]; [foundButton addTarget:self action:@selector(foundButtonCLicked:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:foundButton]; // 注册按钮 UIButton * registButton = [UIButton buttonWithType:UIButtonTypeCustom]; [registButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; registButton.frame = CGRectMake(260, 260, 60, 40); [registButton setTitle:@"注册" forState:UIControlStateNormal]; [registButton addTarget:self action:@selector(registButtonCLicked:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:registButton]; } - (void)loginButtonCLicked:(id)sender { UITextField * textField = (UITextField *)[self.view viewWithTag:1000]; UITextField * textField1 = (UITextField *)[self.view viewWithTag:2000]; if ([textField.text isEqualToString:@""]) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"傻逼" message:@"用户名不能为空" delegate:nil cancelButtonTitle:@"返回" otherButtonTitles:nil, nil]; [alertView show]; [alertView release]; } else if ([textField.text isEqualToString:@"yu"]) { if ([textField1.text isEqualToString:@"123"]) { UIAlertView *successView = [[UIAlertView alloc] initWithTitle:@"么么哒" message:@"您登录成功" delegate:self cancelButtonTitle:@"back" otherButtonTitles:nil, nil]; [successView show]; [successView release]; } else if(![textField1.text isEqualToString:@"123"] && ![textField1.text isEqualToString:@""]) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"(☆_☆)" message:@"你确定密码对么?" delegate:nil cancelButtonTitle:@"返回" otherButtonTitles:nil, nil]; [alertView show]; [alertView release]; } } if([textField1.text isEqualToString:@""]){ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"(☆_☆)" message:@"请输入密码!!!" delegate:nil cancelButtonTitle:@"返回" otherButtonTitles:nil, nil]; [alertView show]; [alertView release]; } else if(![textField.text isEqualToString:@"yu"] && ![textField.text isEqualToString:@""] && ![textField1.text isEqualToString:@""]) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您输入的用户不存在" delegate:nil cancelButtonTitle:@"返回" otherButtonTitles:nil, nil]; [alertView show]; [alertView release]; } } // 找回按钮action - (void)foundButtonCLicked:(id)sender { PassViewController *passVC = [[PassViewController alloc] init]; [self presentViewController:passVC animated:YES completion:^{ }]; [passVC release]; } // 注册按钮action - (void)registButtonCLicked:(id)sender { RegistViewController *registVC = [[RegistViewController alloc] init]; [self presentViewController:registVC animated:YES completion:^{ }]; [registVC release]; } ## import "RegistViewController.h 页面## #import "RegistViewController.h" #import "CustomView.h" @interface RegistViewController () @end @implementation RegistViewController - (void)dealloc { [super dealloc]; } - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { } return self; } - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; // Do any additional setup after loading the view. [self CreateView]; [self creatButton]; } -(void)CreateView { NSArray *aArray = [NSArray arrayWithObjects:@"用户名", @"密码", @"确认密码", @"手机", @"邮箱", nil]; NSArray *bArray = [NSArray arrayWithObjects:@"请输入用户名", @"请输入密码", @"请再次输入", @"请输入手机号", @"请输入邮箱", nil]; int b = 1; for (int i = 0; i < [bArray count]; i++) { NSString *str = [aArray objectAtIndex:i]; CustomView *cus = [[CustomView alloc] initWithFrame:CGRectMake(20, 100 + i * 70, 300, 40) text:str]; cus.leftText.placeholder = [bArray objectAtIndex:i]; cus.leftText.tag = b++; [self.view addSubview:cus]; [cus release]; } } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { for (int i = 1; i < 6; i++) { UITextField * field = (UITextField *)[self.view viewWithTag:i]; [field resignFirstResponder]; } } - (void)creatButton { UIButton * loginButton = [UIButton buttonWithType:UIButtonTypeCustom]; [loginButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; loginButton.frame = CGRectMake(80, 480, 60, 40); [loginButton setTitle:@"注册" forState:UIControlStateNormal]; [loginButton addTarget:self action:@selector(foundButtonAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:loginButton]; UIButton * cancelButton = [UIButton buttonWithType:UIButtonTypeCustom]; [cancelButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; cancelButton.frame = CGRectMake(260, 480, 60, 40); [cancelButton setTitle:@"取消" forState:UIControlStateNormal]; [cancelButton addTarget:self action:@selector(cancelButtonAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:cancelButton]; } - (void)foundButtonAction:(id)sender { } - (void)cancelButtonAction:(id)sender { [self dismissViewControllerAnimated:YES completion:^{ }]; } ## import "PassViewController.h 页面## #import "PassViewController.h" #import "CustomView.h" @interface PassViewController () @end @implementation PassViewController - (void)dealloc { [super dealloc]; } - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { } return self; } - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; // Do any additional setup after loading the view. [self creatView]; } - (void)creatView { UITextField * mail = [[UITextField alloc] initWithFrame:CGRectMake(30, 100, 300, 40)]; mail.placeholder = @"电子邮箱"; mail.borderStyle = UITextBorderStyleRoundedRect; mail.keyboardType = UIKeyboardTypeEmailAddress; mail.clearsOnBeginEditing = YES; mail.tag = 123; [self.view addSubview:mail]; [mail release]; UIButton * foundButton = [UIButton buttonWithType:UIButtonTypeCustom]; [foundButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; foundButton.frame = CGRectMake(80, 160, 60, 40); [foundButton setTitle:@"找回" forState:UIControlStateNormal]; [foundButton addTarget:self action:@selector(foundButtonAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:foundButton]; UIButton * cancelButton = [UIButton buttonWithType:UIButtonTypeCustom]; [cancelButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; cancelButton.frame = CGRectMake(260, 160, 60, 40); [cancelButton setTitle:@"取消" forState:UIControlStateNormal]; [cancelButton addTarget:self action:@selector(cancelButtonAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:cancelButton]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITextField *mail = (UITextField *)[self.view viewWithTag:123]; [mail resignFirstResponder]; } - (void)foundButtonAction:(id)sender { [self dismissViewControllerAnimated:YES completion:^{ }]; } - (void)cancelButtonAction:(id)sender { [self dismissViewControllerAnimated:YES completion:^{ }]; } ## 标题 ## #import <UIKit/UIKit.h> @interface CustomView : UIView<UITextFieldDelegate> @property (nonatomic, retain)UILabel *rightLable; @property (nonatomic, retain)UITextField * leftText; -(instancetype)initWithFrame:(CGRect)frame text:(NSString *)str; @end ## 标题 ## #import "CustomView.h" @implementation CustomView - (void)dealloc { [super dealloc]; [_leftText release]; [_rightLable release]; } - (instancetype)initWithFrame:(CGRect)frame text:(NSString *)str { self = [super initWithFrame:frame]; if (self) { self.rightLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width / 3 - 10, self.frame.size.height)]; _rightLable.textAlignment = NSTextAlignmentLeft; _rightLable.text = str; _rightLable.font = [UIFont boldSystemFontOfSize:20]; [self addSubview:_rightLable]; [_rightLable release]; self.leftText = [[UITextField alloc] initWithFrame:CGRectMake(self.frame.size.width / 3 + 20, 0, self.frame.size.width * 2 / 3 + 10, self.frame.size.height)]; _leftText.font = [UIFont systemFontOfSize:20]; _leftText.clearsOnBeginEditing = YES; _leftText.borderStyle = UITextBorderStyleRoundedRect; [self addSubview:_leftText]; [_leftText release]; } return self; } - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; }
相关文章推荐
- web.xml配置文件总结
- Linux下MySQL数据库的备份与还原
- 截屏 高斯模糊效果
- 我的笔记
- cmd进入控制Mysql&出现乱码的问题
- 数据结构实践项目——文件
- 换机日记
- SAP Client Copy 过程
- scala 实现类似reduceByWindown的效果
- listview下拉刷新 上拉(滑动分页)加载更多
- Domino 使用递归算法获取视图值
- 论文选题依据
- cocods pod重新指向
- java中包命名常见规则
- JavaScript动态创建form表单并提交的实现方法
- C盘不能新建文件的问题解决办法
- 图片数据&大文本数据存储
- iptables禁止来源IP访问限制
- Oracle数据库学习<三>
- 测试工程师必须掌握的技能:测试用例设计步骤