UI4

it2024-10-28  19

// // ViewController.h // UI4_注册登录界面 // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import <UIKit/UIKit.h> #import "RegisterViewController.h" @interface ViewController : UIViewController <UITextFieldDelegate,SendDelegateReport> @end // // ViewController.m // UI4_注册登录界面 // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import "ViewController.h" #import "RegisterViewController.h" #import "LoginViewController.h" @interface ViewController () { RegisterViewController *regis; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSArray *textArray = @[@"用户名",@"密码"]; NSArray *titles = @[@"注册",@"登录"]; CGFloat size = (self.view.frame.size.width-150)/2; for (int i=0; i<2; i++) { UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 100+80*i, 80, 50)]; label.text = textArray[i]; label.textAlignment = NSTextAlignmentCenter; label.font = [UIFont boldSystemFontOfSize:24]; label.textColor = [UIColor redColor]; //label.backgroundColor = [UIColor whiteColor]; [self.view addSubview:label]; UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 100+80*i, self.view.frame.size.width-120, 50)]; textField.borderStyle = UITextBorderStyleRoundedRect; NSString *holder = [NSString stringWithFormat:@"请输入%@", textArray[i]]; textField.placeholder = holder; textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; textField.returnKeyType = UIReturnKeyDone; textField.tag = 200+i; textField.delegate = self; [self.view addSubview:textField]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(50+i*(size+50), 400, size, 50); //btn.backgroundColor = [UIColor cyanColor]; [btn setTitle:titles[i] forState:UIControlStateNormal]; btn.titleLabel.font = [UIFont systemFontOfSize:24]; btn.tag = 300+i; [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; } self.view.backgroundColor = [UIColor yellowColor]; } - (void)btnClicked:(UIButton *)btn { if (btn.tag == 300) { //注册 regis = [[RegisterViewController alloc] init]; regis.delegate = self;//设置代理 // regis.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; // [self presentViewController:regis animated:YES completion:nil]; [self.view addSubview:regis.view]; } else if (btn.tag==301) { //登录 LoginViewController *login = [[LoginViewController alloc] init]; login.modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self presentViewController:login animated:YES completion:nil]; } } #pragma mark ---SendDelegateReport--- - (void)sendName:(NSString *)name andPassword:(NSString *)password { UITextField *textField1 = (UITextField *)[self.view viewWithTag:200]; UITextField *textField2 = (UITextField *)[self.view viewWithTag:201]; textField1.text = name; textField2.text = password; } #pragma mark ---UITextFiledDelegate--- - (BOOL)textFieldShouldReturn:(UITextField *)textField { //隐藏键盘 [textField resignFirstResponder]; return YES; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end

 

// // RegProtocol.h // UI4_注册登录界面 // // Created by qianfeng on 15/7/4. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import <Foundation/Foundation.h> @protocol SendDelegateReport <NSObject> - (void)sendName:(NSString *)name andPassword:(NSString *)password; @end

 

// // RegisterViewController.h // UI4_注册登录界面 // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import <UIKit/UIKit.h> #import "SendDelegateReport.h" //制定协议 //@protocol SendDelegateReport <NSObject> // //- (void)sendName:(NSString *)name andPassword:(NSString *)password; // //@end @interface RegisterViewController : UIViewController <UITextFieldDelegate> @property (assign, nonatomic) id <SendDelegateReport>delegate; @end // // RegisterViewController.m // UI4_注册登录界面 // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import "RegisterViewController.h" #import "ViewController.h" @interface RegisterViewController () { ViewController *v; } @end @implementation RegisterViewController - (void)viewDidLoad { [super viewDidLoad]; v = [[ViewController alloc] init]; // Do any additional setup after loading the view. NSArray *textArray = @[@"用户名",@"密码",@"邮箱"]; for (int i=0; i<3; i++) { UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 100+i*80, 80, 50)]; label.text = textArray[i]; label.textAlignment = NSTextAlignmentCenter; label.font = [UIFont systemFontOfSize:24]; [self.view addSubview:label]; UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 100+i*80, self.view.frame.size.width-120, 50)]; textField.borderStyle = UITextBorderStyleRoundedRect; NSString *holder = [NSString stringWithFormat:@"请输入%@", textArray[i]]; textField.tag = 200+i; textField.placeholder =holder; textField.returnKeyType = UIReturnKeyDone; textField.delegate = self; [self.view addSubview:textField]; } CGFloat size = (self.view.frame.size.width-150)/2; NSArray *titles = @[@"取消",@"保存"]; for (int i=0; i<2; i++) { UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(50+(size+50)*i, 400, size, 50); [btn setTitle:titles[i] forState:UIControlStateNormal]; btn.titleLabel.font = [UIFont systemFontOfSize:24]; btn.tag = 300+i; [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; } self.view.backgroundColor = [UIColor cyanColor]; } - (void)btnClicked:(UIButton *)btn { if (btn.tag==300) { //取消 } else if(btn.tag == 301) { //保存 SEL select = NSSelectorFromString(@"sendName:andPassword:"); // self.delegate = v; if ([self.delegate respondsToSelector:select]) { [self.delegate sendName:((UITextField *)[self.view viewWithTag:200]).text andPassword:((UITextField *)[self.view viewWithTag:201]).text]; } } //[self dismissViewControllerAnimated:YES completion:nil]; //[self presentViewController:v animated:YES completion:nil]; if([self.view superview]) { [self.view removeFromSuperview]; } } - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return 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

 

// // LoginViewController.h // UI4_注册登录界面 // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import <UIKit/UIKit.h> @interface LoginViewController : UIViewController @end // // LoginViewController.m // UI4_注册登录界面 // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import "LoginViewController.h" @interface LoginViewController () @end @implementation LoginViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50,200, self.view.frame.size.width-100, 100)]; label.text = @"登录成功"; label.font = [UIFont italicSystemFontOfSize:35]; label.textAlignment = NSTextAlignmentCenter; label.textColor = [UIColor redColor]; [self.view addSubview:label]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(50, 400, self.view.frame.size.width-100, 50); [btn setTitle:@"退出登录" forState:UIControlStateNormal]; btn.titleLabel.font = [UIFont systemFontOfSize:24]; [btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; self.view.backgroundColor = [UIColor greenColor]; } - (void)btnClicked { [self dismissViewControllerAnimated:YES completion:nil]; } - (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

 

转载于:https://www.cnblogs.com/0515offer/p/4638617.html

相关资源:数据结构—成绩单生成器
最新回复(0)