//
Appdelegate.m
Ui_lesson2_homework
//
Created by Li Hongpeng on 15/7/1.
Copyright (c) 2015 Li Hongpeng. All rights reserved.
//
#import "AppDelegate.h"
@interface Appdelegate ()
@property (nonatomic, copy) NSString *username; User name
@property (nonatomic, copy) NSString *password; Password
@property (nonatomic, retain) UIView *loginview; Login interface
@property (nonatomic, retain) UIView *findpasswordview; Retrieve password interface
@property (nonatomic, retain) UIView *registview; Registration interface
@end
@implementation Appdelegate
-(void) dealloc
{
[_username release];
[_password release];
[_loginview release];
[_findpasswordview release];
[_registview release];
[Super Dealloc];
}
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {
Self.window = [[[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds] autorelease];
Self.window.backgroundColor = [Uicolor Whitecolor];
[Self.window makekeyandvisible];
Self.username = @ "root";
Self.password = @ "123456";
#pragma mark-------Login
Self.loginview = [[[UIView Alloc]initwithframe:self.window.bounds] autorelease];
Self.loginView.backgroundColor = [Uicolor Magentacolor];
[Self.window Addsubview:_loginview];
User
UILabel *namelabel = [[[UILabel Alloc]initwithframe:cgrectmake] autorelease];
Namelabel.text = @ "user name";
[Self.loginview Addsubview:namelabel];
Uitextfield *namefield = [[[[Uitextfield Alloc] Initwithframe:cgrectmake ((a)] autorelease];
Namefield.placeholder = @ "Please enter user name";
Namefield.tag = 200;
Namefield.borderstyle = Uitextborderstyleroundedrect;
[Self.loginview Addsubview:namefield];
Set up Proxy
Namefield.delegate = self;
#pragma mark-------Password
UILabel *passwordlabel = [[[UILabel Alloc] Initwithframe:cgrectmake (+, +, +)] autorelease];
Passwordlabel.text = @ "password";
[Self.loginview Addsubview:passwordlabel];
Uitextfield *passwordfield = [[[Uitextfield Alloc] Initwithframe:cgrectmake (------------)] autorelease];
Passwordfield.placeholder = @ "Please enter password";
Passwordfield.securetextentry = YES;
Passwordfield.borderstyle = Uitextborderstyleroundedrect;
Passwordfield.tag = 201;
[Self.loginview Addsubview:passwordfield];
Set up Proxy
Passwordfield.delegate = self;
Looping Create button
Nsarray *titles = @[@ "Login", @ "Recover password", @ "register"]; Grammar sugar
for (int i = 0; i < 3; i++) {
UIButton *button = [UIButton Buttonwithtype:uibuttontypesystem];
Button.frame = CGRectMake (+ + +) * I, 200, 105, 40);
Dynamic Assignment Title
[Button settitle:titles[i] forstate:uicontrolstatenormal];
Button.tag = + i;
[_loginview Addsubview:button];
}
Get button
UIButton *button1 = (UIButton *) [Self.loginview viewwithtag:100];
UIButton *button2 = (UIButton *) [Self.loginview viewwithtag:101];
UIButton *button3 = (UIButton *) [Self.loginview viewwithtag:102];
Add Event for Button
[Button1 addtarget:self Action: @selector (loginaction:) forcontrolevents:uicontroleventtouchupinside];
[Button2 addtarget:self Action: @selector (passwordaction:) forcontrolevents:uicontroleventtouchupinside];
[Button3 addtarget:self Action: @selector (registaction:) forcontrolevents:uicontroleventtouchupinside];
#pragma mark-----------Retrieve the password---------
Create a retrieve password interface
Self.findpasswordview = [[[UIView alloc] initWithFrame:self.window.bounds] autorelease];
Self.findpassWordView.backgroundColor = [Uicolor Bluecolor];
[Self.window AddSubview:self.findpassWordView];
Input box
Uitextfield *emailfield = [[[[Uitextfield Alloc] Initwithframe:cgrectmake ([[]] 275];
Emailfield.placeholder = @ "Please enter the correct mailbox";
Emailfield.borderstyle = Uitextborderstyleroundedrect;
[Self.findpasswordview Addsubview:emailfield];
Retrieve button
UIButton *findbutton = [UIButton Buttonwithtype:uibuttontypesystem];
Findbutton.frame = CGRectMake (100, 150, 70, 40);
[Findbutton settitle:@ "find" forstate:uicontrolstatenormal];
[Findbutton addtarget:self Action: @selector (findaction:) forcontrolevents:uicontroleventtouchupinside];
[_findpasswordview Addsubview:findbutton];
Cancel
UIButton *canlebutton = [UIButton Buttonwithtype:uibuttontypesystem];
Canlebutton.frame = CGRectMake (205, 150, 70, 40);
[Canlebutton settitle:@ "Cancel" forstate:uicontrolstatenormal];
[Canlebutton addtarget:self Action: @selector (canaleaction:) forControlEvents: (UIControlEventTouchUpInside)];
[_findpasswordview Addsubview:canlebutton];
#pragma Mark--------------------Registration screen
Create a registration interface
Self.registview = [[[UIView alloc] initWithFrame:self.window.bounds] autorelease];
Self.registView.backgroundColor = [Uicolor Yellowcolor];
[Self.window AddSubview:self.registView];
Create an array
Nsarray *labeltext = @[@ "username", @ "password", @ "Confirm password", @ "phone number", @ "Mailbox"];
Nsarray *placeholders = @[@ "Please enter user name", @ "Please enter password", @ "Confirm password", @ "Please enter the phone number", @ "Please enter the mailbox"];
Looping Create
for (int i = 0; i < Labeltext.count; i++) {
UILabel *label = [[[UILabel Alloc] Initwithframe:cgrectmake (+ (+ +) * I, (+)] autorelease];
Label.text = Labeltext[i];
[_registview Addsubview:label];
Uitextfield *TF = [[[Uitextfield Alloc] Initwithframe:cgrectmake (+ + (+ +) * I, (+)] autorelease];
Tf.placeholder = Placeholders[i];
Tf.borderstyle = Uitextborderstyleroundedrect;
Tf.tag = + i;
Tf.delegate = self;
Ciphertext
if (i = = 1 | | i = = 2) {
Tf.securetextentry = YES;
}
[_registview ADDSUBVIEW:TF];
}
UIButton *findbutton2 = [UIButton Buttonwithtype:uibuttontypesystem];
Findbutton2.frame = CGRectMake (100, 400, 100, 100);
Findbutton2.backgroundcolor = [Uicolor Redcolor];
[FindButton2 settitle:@ "Login" forstate: (UIControlStateNormal)];
[FindButton2 addtarget:self Action: @selector (findbutton2action:) forControlEvents: (UIControlEventTouchUpInside)];
[Self.registview Addsubview:findbutton2];
UIButton *cancelbutton = [UIButton Buttonwithtype:uibuttontypesystem];
Cancelbutton.frame = CGRectMake (200, 400, 100, 100);
Cancelbutton.backgroundcolor = [Uicolor Greencolor];
[CancelButton addtarget:self Action: @selector (cancelaction:) forControlEvents: (UIControlEventTouchUpInside)];
[Self.registview Addsubview:cancelbutton];
Insert login interface for each run
[Self.window BringSubviewToFront:self.loginView];
return YES;
}
Cancel button
-(void) Cancelaction: (UIButton *) sender
{
[Self.window BringSubviewToFront:self.loginView];
}
-(void) Findbutton2action: (UIButton *) sender
{
Uialertview *alertview = [[Uialertview alloc] initwithtitle:@ "hint" Message:nil delegate:nil cancelbuttontitle:nil otherbuttontitles:@ "Confirmation", nil];
Show different information by judging
Uitextfield *NAMETF = (Uitextfield *) [Self.registview viewwithtag:300];
Uitextfield *PASSWORDTF = (Uitextfield *) [Self.registview viewwithtag:301];
Uitextfield *PASSWORDTF2 = (Uitextfield *) [Self.registview viewwithtag:302];
if ((NameTF.text.length > 0 | | passWordTF.text.length > 0 | | passWordTF2.text.length = 0) && [passwordtf.te XT IsEqualToString:passWordTF2.text]) {
Record update, new account password
Self.username = Nametf.text;
Self.password = Passwordtf.text;
Registration No problem
Alertview.message = [NSString stringwithformat:@ "Registration successful!\n new user name%@\n password%@", Self.username, Self.password];
[Alertview show];
}else{
Alertview.message = @ "failed to register";
}
[Alertview show];
[Alertview release];
}
Retrieve event
-(void) Findaction: (UIButton *) sender
{
Uialertview *alert = [[[Uialertview alloc] initwithtitle:@ "account information" Message:nil Delegate:nil Cancelbuttontitle:nil otherbuttontitles:@ "", Nil] autorelease];
Alert.message = [NSString stringwithformat:@ "account%@\n password%@", _username, _password];
[Alert show];
}
Cancel Event
-(void) Canaleaction: (UIButton *) sender
{
Tell the registration screen to move to the front
[Self.window Bringsubviewtofront:_loginview];
}
Login Events
-(void) Loginaction: (UIButton *) sender
{
Uialertview *alertview = [[[Uialertview alloc]initwithtitle:@ ' notification ' message:nil delegate:self cancelButtonTitle:@ ' Cancel ' otherbuttontitles:@ "Confirmation", Nil] autorelease];
Whether different information is displayed correctly based on the user name password
Get input Box
Uitextfield *TF1 = (Uitextfield *) [Self.loginview viewwithtag:200];
Uitextfield *TF2 = (Uitextfield *) [Self.loginview viewwithtag:201];
if ([Tf1.text isEqualToString:self.userName] && [Tf2.text IsEqualToString:self.passWord]) {
Alertview.message = @ "Welcome back!";
}else
{
Alertview.message = @ "User name or password error";
}
[Alertview show];
}
Retrieve password
-(void) Passwordaction: (UIButton *) sender
{
[Self.window Bringsubviewtofront:_findpasswordview];
}
Register button
-(void) Registaction: (UIButton *) sender
{
[Self.window BringSubviewToFront:self.registView];
}
-(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField
{
Cancel First Responder
[TextField Resignfirstresponder];
return YES;
}
-(void) Applicationwillresignactive: (uiapplication *) Application {
Sent when the application are about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or when the US Er quits the application and it begins the transition to the background state.
Use the This method to the 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 the This method to release the shared resources, save user data, invalidate timers, and store enough application state info Rmation to the restore your application to the 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's can undo many of the changes made on entering the background.
}
-(void) Applicationdidbecomeactive: (uiapplication *) Application {
Restart any tasks this were paused (or not yet started) while the application is inactive. If the application is previously in the background, optionally refresh the user interface.
}
-(void) Applicationwillterminate: (uiapplication *) Application {
Called when the application are about to terminate. Save data if appropriate. See also Applicationdidenterbackground:.
}
@end
Login page, retrieve password, register page (three view toggle)