您的位置:首页 > 产品设计 > UI/UE

iOS UI03_登陆+注册 UI1~3系统归纳

2015-08-03 08:33 351 查看
完成登陆系统(登陆、注册、找回密码),使用容器视图控制器实现。
定义容器视图控制器ContainerViewController,指定为window的根视图控制器。
定义LoginViewController、RegistViewController、PasswordViewController,三个视图控制器的根视图添加到容器视图控制器的根视图。


//
//  AppDelegate.m
//  UI作业03
//
//  Created by dllo on 15/7/31.
//  Copyright (c) 2015年 zhozhicheng. All rights reserved.
//

#import "AppDelegate.h"
#import "LoginViewController.h"
#import "RegistViewController.h"
#import "PasswordViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate
-(void)dealloc
{
[_window self];
[super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[_window release];

//windows设置的根视图是LoginViewController
LoginViewController *loginVC = [[LoginViewController alloc] init];
self.window.rootViewController=loginVC;
[loginVC 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


//
//  LTView.h
//  UI作业03
//
//  Created by dllo on 15/7/31.
//  Copyright (c) 2015年 zhozhicheng. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface LTView : UIView<UITextFieldDelegate>
//两个对应的输入框
@property(nonatomic,retain)UILabel *loadLabel1;
@property(nonatomic,retain)UILabel *loadLabel2;
@property(nonatomic,retain)UITextField *loadTextField1;
@property(nonatomic,retain)UITextField *loadTextField2;

@property(nonatomic,retain)UILabel *confirmLabel;
@property(nonatomic,retain)UILabel *numLabel;
@property(nonatomic,retain)UILabel *emailLabel;
@property(nonatomic,retain)UITextField *confirmTextField;
@property(nonatomic,retain)UITextField *numTextField;
@property(nonatomic,retain)UITextField *emailTextField;
@end


//
//  LTView.m
//  UI作业03
//
//  Created by dllo on 15/7/31.
//  Copyright (c) 2015年 zhozhicheng. All rights reserved.
//

#import "LTView.h"

@implementation LTView

//重写init方法,模块化
-(instancetype)initWithFrame:(CGRect)frame
{
self=[super initWithFrame:frame];
if (self) {
[self createView];
}
return self;
}

-(void)createView
{
//建立两个登陆页面的label视图
self.loadLabel1=[[UILabel alloc] initWithFrame:CGRectMake(80, 150, 100, 40)];
[self addSubview:self.loadLabel1];
[_loadLabel1 release];

self.loadLabel2=[[UILabel alloc] initWithFrame:CGRectMake(80, 200, 100, 40)];
[self addSubview:self.loadLabel2];
[_loadLabel2 release];
//建立两个登陆页面的textfield
self.loadTextField1=[[UITextField alloc] initWithFrame:CGRectMake(150, 150, 150, 40)];
self.loadTextField1.layer.borderWidth=1;
self.loadTextField1.layer.cornerRadius=10;
[self addSubview:self.loadTextField1];
//代理人
self.loadTextField1.delegate=self;
[_loadTextField1 release];

self.loadTextField2=[[UITextField alloc] initWithFrame:CGRectMake(150, 200, 150, 40)];
self.loadTextField2.layer.borderWidth=1;
self.loadTextField2.layer.cornerRadius=10;
[self addSubview:self.loadTextField2];
//代理人
self.loadTextField2.delegate=self;
[_loadTextField2 release];

}

@end


//
//  LoginViewController.m
//  UI作业03
//
//  Created by dllo on 15/7/31.
//  Copyright (c) 2015年 zhozhicheng. All rights reserved.
//

#import "LoginViewController.h"
#import "LTView.h"
#import "RegistViewController.h"
#import "PasswordViewController.h"

@interface LoginViewController ()<UITextFieldDelegate,UIAlertViewDelegate>
@property(nonatomic,retain)UILabel *textlabel;
@property(nonatomic,retain)UIAlertView *alertView;
@property(nonatomic,assign)BOOL isSelected;

@end

@implementation LoginViewController
-(void)dealloc
{

[_alertView release];
[_textlabel release];
[super dealloc];
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor yellowColor];
//铺设登陆页面的魔化块
//建立一个LTView视图
LTView *view1=[[LTView alloc] initWithFrame:CGRectMake(0, 0, 350, 500)];
[self.view addSubview:view1];
[view1 release];
//显示相应的文字
view1.loadLabel1.text=@"用户名";
view1.loadLabel2.text=@"密码";
view1.loadTextField1.placeholder=@"请输入账号";
view1.loadTextField2.placeholder=@"请输入密码";
view1.tag = 1000;
//密码隐藏
view1.loadTextField2.secureTextEntry=YES;
//全部清除按钮
view1.loadTextField1.clearButtonMode=UITextFieldViewModeAlways;
view1.loadTextField2.clearButtonMode=UITextFieldViewModeAlways;
//回收键盘的代理人
view1.loadTextField1.delegate=self;
view1.loadTextField2.delegate=self;
//铺设三个button
UIButton *loadButton=[UIButton buttonWithType:UIButtonTypeSystem];
//BUTTON位置
loadButton.frame=CGRectMake(70, 300, 50, 25);
//button文字
[loadButton setTitle:@"登陆" forState:UIControlStateNormal];
[self.view addSubview:loadButton];
//设置button框,圆角
loadButton.layer.borderWidth=1;
loadButton.layer.cornerRadius=10;
//设置button方法
[loadButton addTarget:self action:@selector(loadClick:) forControlEvents:UIControlEventTouchUpInside];

UIButton *findButton=[UIButton buttonWithType:UIButtonTypeSystem];
findButton.frame=CGRectMake(150, 300, 70, 25);
[findButton setTitle:@"找回密码" forState:UIControlStateNormal];
[self.view addSubview:findButton];
findButton.layer.borderWidth=1;
findButton.layer.cornerRadius=10;
[findButton addTarget:self action:@selector(findClick:) forControlEvents:UIControlEventTouchUpInside];

UIButton *registerButton=[UIButton buttonWithType:UIButtonTypeSystem];
registerButton.frame=CGRectMake(250, 300, 50, 25);
[registerButton setTitle:@"注册" forState:UIControlStateNormal];
[self.view addSubview:registerButton];
registerButton.layer.borderWidth=1;
registerButton.layer.cornerRadius=10;
[registerButton addTarget:self action:@selector(registerClick:) forControlEvents:UIControlEventTouchUpInside];

//设置显示密码按钮图片的更换
UIButton *picButton=[UIButton buttonWithType:UIButtonTypeCustom];
picButton.frame=CGRectMake(130,250, 30, 30);
[picButton setImage:[UIImage imageNamed:@"check.png" ] forState:UIControlStateNormal];
[self.view addSubview:picButton];
[picButton addTarget:self action:@selector(changeImage:) forControlEvents:UIControlEventTouchUpInside];
//文字 显示内容
self.textlabel=[[UILabel alloc] initWithFrame:CGRectMake(180, 250, 150, 30)];
self.textlabel.text=@"显示内容";
[self.view addSubview:self.textlabel];
[self.textlabel release];
// 报错
self.alertView=[[UIAlertView alloc] initWithTitle:@"报错" message:@"账号密码有误"  delegate:self cancelButtonTitle:@"重新输入" otherButtonTitles:@"找回密码", nil];

}
//回收键盘的实现,之前需要签订协议
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
//图片显示内容切换,
-(void)changeImage:(UIButton *)picButton{
if (picButton.selected) {
//切换点击之后的两种图片状态
[picButton setImage:[UIImage imageNamed:@"check.png"]  forState:UIControlStateNormal];
}else{
[picButton setImage:[UIImage imageNamed:@"checked.png"]  forState:UIControlStateNormal];
}

picButton.selected =!picButton.selected;
((LTView *)[self.view viewWithTag:1000]).loadTextField2.secureTextEntry ^= 1;
self.isSelected = !self.isSelected;
}

//判断账号密码的实现
-(void)loadClick:(UIButton *)loadButton
{
if ( ![((LTView *)[self.view viewWithTag:1000]).loadTextField1.text isEqualToString:@"1104010303"] || ![((LTView *)[self.view viewWithTag:1000]).loadTextField2.text isEqualToString:@"920928"]) {
[self.alertView show];

}
}

-(void)findClick:(UIButton *)findButton
{
RegistViewController *registVC=[[RegistViewController alloc] init];
[registVC setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:registVC animated:YES completion:^{
}];
[registVC release];
}

-(void)registerClick:(UIButton *)registerButton
{
PasswordViewController *passWordVC=[[PasswordViewController alloc] init];
[passWordVC setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:passWordVC animated:YES completion:^{
}];
//    [passWordVC release];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
RegistViewController *registVC = [[RegistViewController alloc] init];
[registVC setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:registVC animated:YES completion:^{

}];

}
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end


//
//  RegistViewController.m
//  UI作业03
//
//  Created by dllo on 15/7/31.
//  Copyright (c) 2015年 zhozhicheng. All rights reserved.
//

#import "RegistViewController.h"

@interface RegistViewController ()<UITextFieldDelegate>
@property(nonatomic,retain)UITextField *emailTextField;

@end

@implementation RegistViewController
-(void)dealloc
{
[_emailTextField release];
[super dealloc];
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//当前页面背景
self.view.backgroundColor=[UIColor cyanColor];
//建立email输入框
self.emailTextField=[[UITextField alloc] initWithFrame:CGRectMake(100, 200, 200, 40)];
[self.view addSubview:self.emailTextField];
self.emailTextField.layer.borderWidth=1;
self.emailTextField.layer.cornerRadius=10;
self.emailTextField.placeholder=@"电子邮箱";
//建立此页面的两个button
UIButton *findButton=[UIButton buttonWithType:UIButtonTypeSystem];
findButton.frame=CGRectMake(120, 280, 40, 25);
[findButton setTitle:@"找回" forState:UIControlStateNormal];
[self.view addSubview:findButton];
findButton.layer.borderWidth=1;
findButton.layer.cornerRadius=10;
[findButton addTarget:self action:@selector(findClick:) forControlEvents:UIControlEventTouchUpInside];

UIButton *abolishButton=[UIButton buttonWithType:UIButtonTypeSystem];
abolishButton.frame=CGRectMake(200, 280, 40, 25);
[abolishButton setTitle:@"取消" forState:UIControlStateNormal];
[self.view addSubview:abolishButton];
abolishButton.layer.borderWidth=1;
abolishButton.layer.cornerRadius=10;
[abolishButton addTarget:self action:@selector(abolishClick:) forControlEvents:UIControlEventTouchUpInside];

}

-(void)abolishClick:(UIButton *)button
{
[self dismissViewControllerAnimated:YES completion:^{

}];
}
-(void)findClick:(UIButton *)findButton
{

}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end


//
//  PasswordViewController.m
//  UI作业03
//
//  Created by dllo on 15/7/31.
//  Copyright (c) 2015年 zhozhicheng. All rights reserved.
//

#import "PasswordViewController.h"
#import "LTView.h"
#import "LoginViewController.h"
#define HEIGHT self.view.frame.size.height
@interface PasswordViewController ()<UITextFieldDelegate,UIAlertViewDelegate>
@property(nonatomic,retain)UILabel *loadLabel1;
@property(nonatomic,retain)UILabel *loadLabel2;
@property(nonatomic,retain)UILabel *confirmLabel;
@property(nonatomic,retain)UILabel *numLabel;
@property(nonatomic,retain)UILabel *emailLabel;
@property(nonatomic,retain)UITextField *loadTextField1;
@property(nonatomic,retain)UITextField *loadTextField2;
@property(nonatomic,retain)UITextField *confirmTextField;
@property(nonatomic,retain)UITextField *numTextField;
@property(nonatomic,retain)UITextField *emailTextField;
@property(nonatomic,retain)UIAlertView *alertView;

@end

@implementation PasswordViewController
-(void)dealloc
{
[_loadLabel1 release];
[_loadLabel2 release];
[_confirmLabel release];
[_numLabel release];
[_emailLabel release];
[_loadTextField1 release];
[_loadTextField2 release];
[_confirmTextField release];
[_numTextField release];
[_emailTextField release];
[_alertView release];
[super dealloc];

}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

self.view.backgroundColor=[UIColor redColor];

self.loadLabel1=[[UILabel alloc] initWithFrame:CGRectMake(60, 150, 70, 40)];
[self.view addSubview:self.loadLabel1];
self.loadLabel1.layer.borderWidth = 1;
self.loadLabel1.layer.cornerRadius =10;
self.loadLabel1.text=@"用户名";
[_loadLabel1 release];

self.loadLabel2=[[UILabel alloc] initWithFrame:CGRectMake(60, 200, 70, 40)];
[self.view addSubview:self.loadLabel2];
self.loadLabel2.layer.borderWidth = 1;
self.loadLabel2.layer.cornerRadius =10;
self.loadLabel2.text=@"密码";
[_loadLabel2 release];

self.confirmLabel=[[UILabel alloc] initWithFrame:CGRectMake(60, 250, 70, 40)];
[self.view addSubview:self.confirmLabel];
self.confirmLabel.layer.borderWidth = 1;
self.confirmLabel.layer.cornerRadius =10;
self.confirmLabel.text=@"确认密码";
[_confirmLabel release];

self.numLabel=[[UILabel alloc] initWithFrame:CGRectMake(60, 300, 70, 40)];
[self.view addSubview:self.numLabel];
self.numLabel.layer.borderWidth = 1;
self.numLabel.layer.cornerRadius =10;
self.numLabel.text=@"手机号";
[_numLabel release];

self.emailLabel=[[UILabel alloc] initWithFrame:CGRectMake(60, 350, 70, 40)];
[self.view addSubview:self.emailLabel];
self.emailLabel.layer.borderWidth = 1;
self.emailLabel.layer.cornerRadius =10;
self.emailLabel.text=@"邮箱";
[_emailLabel release];

// TEXTFIELD

self.loadTextField1=[[UITextField alloc] initWithFrame:CGRectMake(150, 150, 150, 40)];
self.loadTextField1.layer.borderWidth=1;
self.loadTextField1.layer.cornerRadius=10;
self.loadTextField1.placeholder=@"请输入用户名";
self.loadTextField1.clearButtonMode=UITextFieldViewModeAlways;
[self.view addSubview:self.loadTextField1];
//代理人
self.loadTextField1.delegate=self;
[_loadTextField1 release];

self.loadTextField2=[[UITextField alloc] initWithFrame:CGRectMake(150, 200, 150, 40)];
self.loadTextField2.layer.borderWidth=1;
self.loadTextField2.layer.cornerRadius=10;
self.loadTextField2.placeholder=@"请输入密码";
self.loadTextField2.secureTextEntry=YES;
self.loadTextField2.clearButtonMode=UITextFieldViewModeAlways;
[self.view addSubview:self.loadTextField2];
self.loadTextField2.delegate=self;
[_loadTextField2 release];

self.confirmTextField=[[UITextField alloc] initWithFrame:CGRectMake(150, 250, 150, 40)];
self.confirmTextField.layer.borderWidth=1;
self.confirmTextField.layer.cornerRadius=10;
self.confirmTextField.placeholder=@"再次输入密码";
self.confirmTextField.secureTextEntry=YES;
self.confirmTextField.clearButtonMode=UITextFieldViewModeAlways;
[self.view addSubview:self.confirmTextField];
self.confirmTextField.delegate=self;
[_confirmLabel release];

self.numTextField=[[UITextField alloc] initWithFrame:CGRectMake(150, 300, 150, 40)];
self.numTextField.layer.borderWidth=1;
self.numTextField.layer.cornerRadius=10;
self.numTextField.placeholder=@"请输入联系方式";
self.numTextField.clearButtonMode=UITextFieldViewModeAlways;
[self.view addSubview:self.numTextField];
self.confirmTextField.delegate=self;
[_numTextField release];

self.emailTextField=[[UITextField alloc] initWithFrame:CGRectMake(150, 350, 150, 40)];
self.emailTextField.layer.borderWidth=1;
self.emailTextField.layer.cornerRadius=10;
self.emailTextField.placeholder=@"请输入邮箱";
self.emailTextField.clearButtonMode=UITextFieldViewModeAlways;
[self.view addSubview:self.emailTextField];
self.emailTextField.delegate=self;
[_emailTextField release];

//注册按钮
UIButton *registerButton=[UIButton buttonWithType:UIButtonTypeSystem];
registerButton.frame=CGRectMake(110, 460, 50, 25);
[registerButton setTitle:@"注册" forState:UIControlStateNormal];
[self.view addSubview:registerButton];
registerButton.layer.borderWidth=1;
registerButton.layer.cornerRadius=10;
[registerButton addTarget:self action:@selector(registerClick:) forControlEvents:UIControlEventTouchUpInside];

//取消按钮
UIButton *cancelButton=[UIButton buttonWithType:UIButtonTypeSystem];
cancelButton.frame=CGRectMake(200, 460, 50, 25);
[cancelButton setTitle:@"取消" forState:UIControlStateNormal];
[self.view addSubview:cancelButton];
cancelButton.layer.borderWidth=1;
cancelButton.layer.cornerRadius=10;
[cancelButton addTarget:self action:@selector(cancelClick:) forControlEvents:UIControlEventTouchUpInside];

self.alertView=[[UIAlertView alloc] initWithTitle:@"恭喜" message:@"注册成功" delegate:self cancelButtonTitle:@"返回登陆页面" otherButtonTitles:@"取消", nil];

}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if (textField.frame.origin.y > HEIGHT / 2) {
//先做一个差值
CGFloat height =textField.frame.origin.y- HEIGHT / 2;
self.view.center=CGPointMake(self.view.center.x, self.view.center.y - height);
}
return YES;
}
// 等到编译结束的时候,再让他回到原位
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
if (textField.frame.origin.y > HEIGHT / 2) {
CGFloat height =textField.frame.origin.y- HEIGHT / 2;
self.view.center=CGPointMake(self.view.center.x, self.view.center.y + height);
}
return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}

-(void)cancelClick:(UIButton *)cancelButton
{
[self dismissViewControllerAnimated:YES completion:^{

}];
}

-(void)registerClick:(UIButton *)button
{
[self.alertView show];

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
LoginViewController *loginVC = [[LoginViewController alloc] init];
[loginVC setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:loginVC animated:YES completion:^{

}];
[loginVC release];
}
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: