创建三个页⾯面,要求: 1.登陆页⾯面LoginViewController,可以输⼊入⽤用户名和密码, 导航栏右侧放置添加按钮,可以通过添加按钮模态到注册 页⾯面。 2.注册页⾯面RegisterViewController,填写⽤用户名,密码, 确认密码后注册。 3.欢迎页⾯面WelcomeViewController,由登陆页⾯面push得 到。
//
// AppDelegate.h
// UI7_作业2
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//
import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (retain, nonatomic) UIWindow *window;
@end
//
// AppDelegate.m
// UI7_作业2
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//
import "AppDelegate.h"
import "RootViewController.h"
import "RegisterViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[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];
RootViewController *rootVC = [[RootViewController alloc]init];
UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:rootVC];
self.window.rootViewController = navi;
[rootVC release];
[navi release];[_window 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
//
// RootViewController.h
// UI7_作业2
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//
import <UIKit/UIKit.h>
@interface RootViewController : UIViewController
@end
//
// RootViewController.m
// UI7_作业2
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//
import "RootViewController.h"
import "RegisterViewController.h"
import "WelcomeViewController.h"
@interface RootViewController ()
@end
@implementation RootViewController
(void)viewDidLoad {
[super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor]; self.title = @"登录"; // 右上角 self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(rightAction)]autorelease]; // 登录按钮 UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(150, 400, 50, 30)]; button.backgroundColor = [UIColor whiteColor]; [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; [button setTitle:@"登录" forState:UIControlStateNormal]; [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; [button release]; // [self login]; [self password];
}
(void)buttonAction
{WelcomeViewController *weVC = [[WelcomeViewController alloc]init]; [self.navigationController pushViewController:weVC animated:YES]; [weVC release];
}
(void)login
{UITextField *text= [[UITextField alloc]initWithFrame:CGRectMake(50, 200, 250, 30)];
// text.backgroundColor = [UIColor redColor];
[self.view addSubview:text]; [text release]; text.placeholder = @"请输入用户名"; text.layer.borderWidth = 1.0; text.layer.cornerRadius = 5;
}
(void)password
{UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(50, 260, 250, 30)];
// text.backgroundColor = [UIColor redColor];
[self.view addSubview:text]; [text release]; text.placeholder = @"请输入密码"; text.secureTextEntry = YES; text.layer.borderWidth = 1.0; text.layer.cornerRadius = 5;
}
- (void)rightAction
{
// RegisterViewController *rsVC = [[RegisterViewController alloc]init];
// [self.navigationController pushViewController:rsVC animated:YES];
// [rsVC release];
RegisterViewController *reVC = [[RegisterViewController alloc]init];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:reVC];
// RegisterViewController * = [[RegisterViewController alloc]init];
//
[self presentViewController:nav animated:YES completion:^{
//
}];
[reVC release];
[nav 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
//
// RegisterViewController.h
// UI7_作业2
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//
import <UIKit/UIKit.h>
@interface RegisterViewController : UIViewController
@end
//
// RegisterViewController.m
// UI7_作业2
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//
import "RegisterViewController.h"
@interface RegisterViewController ()
@end
@implementation RegisterViewController
(void)viewDidLoad {
[super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor]; // 标题 self.title = @"注册"; // 右上角 self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(rightAction)]autorelease]; // 输入框 [self zc]; // 按钮 UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(150, 300, 50, 30)]; button.backgroundColor = [UIColor redColor]; [self.view addSubview:button]; [button release]; [button setTitle:@"返回" forState:UIControlStateNormal]; [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [button addTarget:self action:@selector(button) forControlEvents:UIControlEventTouchUpInside];
}
(void)rightAction
{[self dismissViewControllerAnimated:YES completion:^{ // }];
}
(void)button
{[self dismissViewControllerAnimated:YES completion:^{ NSLog(@"消失"); }];
}
(void)zc
{UITextField *textLogin = [[UITextField alloc]initWithFrame:CGRectMake(30, 120, 300, 30)];
// textLogin.backgroundColor = [UIColor redColor];
[self.view addSubview:textLogin]; [textLogin release]; textLogin.placeholder = @"请输入用户名"; textLogin.layer.borderWidth = 1.0; textLogin.layer.cornerRadius = 5; // m UITextField *textpass = [[UITextField alloc]initWithFrame:CGRectMake(30, 180, 300, 30)];
// textpass.backgroundColor = [UIColor redColor];
[self.view addSubview:textpass]; [textpass release]; textpass.placeholder = @"请输入密码"; textpass.secureTextEntry = YES; textpass.layer.borderWidth = 1.0; textpass.layer.cornerRadius = 5; // mm UITextField *textpassword = [[UITextField alloc]initWithFrame:CGRectMake(30, 240, 300, 30)];
// textpassword.backgroundColor = [UIColor redColor];
[self.view addSubview:textpassword]; [textpassword release]; textpassword.placeholder = @"请输入密码"; textpassword.secureTextEntry = YES; textpassword.layer.borderWidth = 1.0; textpassword.layer.cornerRadius = 5;
}
(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
//
// WelcomeViewController.h
// UI7_作业2
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//
import <UIKit/UIKit.h>
@interface WelcomeViewController : UIViewController
@end
//
// WelcomeViewController.m
// UI7_作业2
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//
import "WelcomeViewController.h"
@interface WelcomeViewController ()
@end
@implementation WelcomeViewController
(void)viewDidLoad {
[super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor]; //标题 self.title = @"欢迎页"; // 欢迎 UILabel *la = [[UILabel alloc]initWithFrame:CGRectMake(100, 150, 100, 30)]; [self.view addSubview:la]; [la release]; la.text = @"Welcome~"; // 按钮 UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(150, 250, 50, 30)]; [self.view addSubview:button]; [button release]; [button setTitle:@"返回" forState:UIControlStateNormal]; [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; [button addTarget:self action:@selector(button) forControlEvents:UIControlEventTouchUpInside];
}
(void)button
{[self.navigationController popToRootViewControllerAnimated:YES];
}
(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