游戏登陆界面完整版
2013-12-09 22:47
274 查看
RootView代码
登陆界面
封装输入框
封装Button
#import "RootViewController.h" #import "HomeView.h" #import "LoginView.h" #import "RegisterView.h" #import "FindPasswordView.h" @interface RootViewController () @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // NSLog(@"this is test"); // Custom initialization //制定初始化方法 //一些公共内容 //必须的参数 或者其他一些东西 } return self; } //viewDidLoad仅在self.view被加载之后执行,一般执行一次 - (void)viewDidLoad { [super viewDidLoad]; HomeView*aView=[[HomeView alloc]initWithFrame:CGRectMake(0, 0, 330, 480)]; aView.tag=1000; [self.view addSubview:aView]; LoginView*bView=[[LoginView alloc]initWithFrame:CGRectMake(0, 0, 330, 480)]; bView.hidden= YES; bView.tag=1004; [self.view addSubview:bView]; FindPasswordView*dView=[[FindPasswordView alloc]initWithFrame:CGRectMake(0, 0, 330, 480)]; dView.hidden=YES; dView.tag=1002; [self.view addSubview:dView]; RegisterView*cView=[[RegisterView alloc]initWithFrame:CGRectMake(0, 0, 330, 480)]; cView.hidden=YES; cView.tag=1003; [self.view addSubview:cView]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
登陆界面
#import "HomeView.h" #import "CustomTextField.h" #import "UIButton+CreatNewButton.h" #define kHomeView 1200 @implementation HomeView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { homeView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 330, 480)]; homeView.center=CGPointMake(158, 260); [homeView setImage:[UIImage imageNamed:@"test.png"]]; homeView.tag = kHomeView; homeView.userInteractionEnabled = YES; [self addSubview:homeView]; CGFloat y = 100; NSArray *titles = [NSArray arrayWithObjects:@"用户名:",@"密码:", nil]; for (int i = 0; i < 2; i++) { CustomTextField *tf = [[CustomTextField alloc] initWithFrame:CGRectMake(60, y, 220, 40) description:[titles objectAtIndex:i]]; tf.tag = i; y += 70; [homeView addSubview:tf]; tf.alpha=0.8; } UIButton *aButton =[UIButton buttonWithType:UIButtonTypeRoundedRect frame:CGRectMake(20, 360, 80, 40) title:@"登陆" target:self action:@selector(login) borderwidth:3 cornerradius:3 alpha:0.8 backgroundColor:[UIColor redColor] setTitleColor:[UIColor redColor]]; aButton.titleLabel.font = [UIFont systemFontOfSize: 22.0]; [self addSubview:aButton]; UIButton *cButton =[UIButton buttonWithType:UIButtonTypeRoundedRect frame:CGRectMake(120, 360, 80, 40) title:@"找回密码" target:self action:@selector(findPassword) borderwidth:3 cornerradius:3 alpha:0.8 backgroundColor:[UIColor redColor] setTitleColor:[UIColor redColor]]; cButton.titleLabel.font = [UIFont systemFontOfSize: 18.0]; [self addSubview:cButton]; UIButton *bButton =[UIButton buttonWithType:UIButtonTypeRoundedRect frame:CGRectMake(220, 360, 80, 40) title:@"注册" target:self action:@selector(registers) borderwidth:3 cornerradius:3 alpha:0.8 backgroundColor:[UIColor redColor] setTitleColor:[UIColor redColor]]; bButton.alpha=0.7; bButton.titleLabel.font = [UIFont systemFontOfSize: 22.0]; [self addSubview:bButton]; } return self; } -(void)login { HomeView *home = (HomeView *)[[self superview] viewWithTag:kHomeView]; CustomTextField *custom = (CustomTextField *)[home viewWithTag:0]; CustomTextField *custom2 = (CustomTextField *)[home viewWithTag:1]; if ([custom.text isEqualToString:@"111"] && [custom2.text isEqualToString:@"111"]) { CustomTextField* view =(CustomTextField *) [[self superview] viewWithTag:1004]; view.hidden = NO; self.hidden=YES; } else { UIAlertView *a = [[UIAlertView alloc]initWithTitle:@"信息" message:@"输入错误" delegate:self cancelButtonTitle:nil otherButtonTitles:@"重新输入", nil]; [a show ]; } } -(void)findPassword { CustomTextField* view=(CustomTextField *) [[self superview]viewWithTag:1002]; view.hidden=NO; self.hidden=YES; } -(void)registers { CustomTextField* view=(CustomTextField *) [[self superview]viewWithTag:1003]; view.hidden=NO; self.hidden=YES; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end登陆成功后界面
#import "LoginView.h" #import "CustomTextField.h" #import "UIButton+CreatNewButton.h" @implementation LoginView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { loginView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 330, 480)]; loginView.center=CGPointMake(158, 260); [loginView setImage:[UIImage imageNamed:@"123.jpg"]]; loginView.userInteractionEnabled = YES; [self addSubview:loginView]; UILabel*loginLabel=[[UILabel alloc]initWithFrame:CGRectMake(110, 120, 100, 60)]; loginLabel.backgroundColor=[UIColor grayColor]; loginLabel.layer.borderWidth=2; loginLabel.layer.cornerRadius=10; loginLabel.alpha=0.9; loginLabel.textAlignment=NSTextAlignmentCenter; loginLabel.text=@"登陆成功"; loginLabel.font=[UIFont systemFontOfSize:22.0]; loginLabel.textColor=[UIColor blackColor]; [self addSubview:loginLabel]; UIButton *backButton = [UIButton buttonWithType:UIButtonTypeRoundedRect frame:CGRectMake(120, 340, 80, 40) title:@"返回" target:self action:@selector(didClickBack) borderwidth:3 cornerradius:3 alpha:0.8 backgroundColor:[UIColor redColor] setTitleColor:[UIColor redColor]]; backButton.userInteractionEnabled = YES; backButton.titleLabel.font = [UIFont systemFontOfSize: 22.0]; [self addSubview:backButton]; } return self; } -(void)didClickBack { CustomTextField* view =(CustomTextField *) [[self superview] viewWithTag:1000]; view.hidden = NO; self.hidden = YES; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end找回密码界面
#import "FindPasswordView.h" #import "CustomTextField.h" #import "UIButton+CreatNewButton.h" @implementation FindPasswordView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { findPasswordView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 330, 480)]; findPasswordView.center=CGPointMake(158, 260); [findPasswordView setImage:[UIImage imageNamed:@"456.jpg"]]; findPasswordView.userInteractionEnabled = YES; [self addSubview:findPasswordView]; CGFloat y = 100; NSArray *titles = [NSArray arrayWithObjects:@"短信追回:",@"邮箱追回:", nil]; for (int i = 0; i < 2; i++) { CustomTextField *tf = [[CustomTextField alloc] initWithFrame:CGRectMake(40, y, 240, 40) description:[titles objectAtIndex:i]]; y += 100; tf.tag = i+2; tf.alpha=0.8; [self addSubview:tf]; } UIButton *backButton = [UIButton buttonWithType:UIButtonTypeRoundedRect frame:CGRectMake(120, 390, 80, 40) title:@"返回" target:self action:@selector(didClickBack) borderwidth:3 cornerradius:3 alpha:0.8 backgroundColor:[UIColor redColor] setTitleColor:[UIColor redColor]]; backButton.userInteractionEnabled = YES; backButton.titleLabel.font = [UIFont systemFontOfSize: 22.0]; [self addSubview:backButton]; UIButton *affirmButton = [UIButton buttonWithType:UIButtonTypeRoundedRect frame:CGRectMake(120, 340, 80, 40) title:@"确定" target:self action:@selector(affirmButton) borderwidth:3 cornerradius:3 alpha:0.8 backgroundColor:[UIColor redColor] setTitleColor:[UIColor redColor]]; affirmButton.userInteractionEnabled = YES; affirmButton.titleLabel.font = [UIFont systemFontOfSize: 22.0]; [self addSubview:affirmButton]; } return self; } -(void)didClickBack { CustomTextField* view =(CustomTextField *) [[self superview] viewWithTag:1000]; view.hidden = NO; self.hidden = YES; } -(void)affirmButton { FindPasswordView *findPassword = (FindPasswordView *)[[self superview] viewWithTag:1002]; CustomTextField *custom = (CustomTextField *)[findPassword viewWithTag:2]; CustomTextField *custom2 = (CustomTextField *)[findPassword viewWithTag:3]; if ([custom.text isEqualToString:@"111"] && [custom2.text isEqualToString:@"111"]) { UIAlertView *a = [[UIAlertView alloc]initWithTitle:@"信息" message:@"密码已经找回" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil]; [a show ]; } else { UIAlertView *a = [[UIAlertView alloc]initWithTitle:@"信息" message:@"输入错误" delegate:self cancelButtonTitle:nil otherButtonTitles:@"重新输入", nil]; [a show ]; } } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end注册界面代码
#import "RegisterView.h" #import "CustomTextField.h" #import "UIButton+CreatNewButton.h" @implementation RegisterView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { registerView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 330, 520)]; registerView.center=CGPointMake(158, 260); [registerView setImage:[UIImage imageNamed:@"789.jpg"]]; registerView.userInteractionEnabled = YES; [self addSubview:registerView]; CGFloat y = 100; NSArray *titles = [NSArray arrayWithObjects:@"用户名:",@"密码:",@"确认密码:",@"邮箱", nil]; for (int i = 0; i < 4; i++) { CustomTextField *tf = [[CustomTextField alloc] initWithFrame:CGRectMake(40, y, 240, 30) description:[titles objectAtIndex:i]]; y += 70; tf.tag = i+4; tf.alpha=0.8; [self addSubview:tf]; } UIButton *affirmButton = [UIButton buttonWithType:UIButtonTypeRoundedRect frame:CGRectMake(40, 380, 80, 40) title:@"确定" target:self action:@selector(affirmButton) borderwidth:3 cornerradius:3 alpha:0.8 backgroundColor:[UIColor redColor] setTitleColor:[UIColor redColor]]; affirmButton.userInteractionEnabled = YES; affirmButton.titleLabel.font = [UIFont systemFontOfSize: 22.0]; [self addSubview:affirmButton]; UIButton *backButton = [UIButton buttonWithType:UIButtonTypeRoundedRect frame:CGRectMake(200, 380, 80, 40) title:@"返回" target:self action:@selector(didClickBack) borderwidth:3 cornerradius:3 alpha:0.8 backgroundColor:[UIColor redColor] setTitleColor:[UIColor redColor]]; backButton.userInteractionEnabled = YES; backButton.titleLabel.font = [UIFont systemFontOfSize: 22.0]; [self addSubview:backButton]; } return self; } -(void)didClickBack { CustomTextField* view =(CustomTextField *) [[self superview] viewWithTag:1000]; view.hidden = NO; self.hidden = YES; } -(void)affirmButton { RegisterView *registerView1 = (RegisterView *)[self viewWithTag:1003]; CustomTextField *custom = (CustomTextField *)[registerView1 viewWithTag:4]; CustomTextField *custom2 = (CustomTextField *)[registerView1 viewWithTag:5]; CustomTextField *custom3 = (CustomTextField *)[registerView1 viewWithTag:6]; CustomTextField *custom4 = (CustomTextField *)[registerView1 viewWithTag:7]; if ([custom.text isEqualToString:@"111"]&& [custom2.text isEqualToString:@"111"]&& [custom4.text isEqualToString:@"111"]&&[custom2.text isEqualToString:custom3.text]) { UIAlertView *a = [[UIAlertView alloc]initWithTitle:@"信息" message:@"注册成功" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil]; [a show ]; } else { UIAlertView *a = [[UIAlertView alloc]initWithTitle:@"信息" message:@"输入错误" delegate:self cancelButtonTitle:nil otherButtonTitles:@"重新输入", nil]; [a show ]; } } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end
封装输入框
- (id)initWithFrame:(CGRect)frame description:(NSString *)description { self = [super initWithFrame:frame]; if (self) { CGFloat width = frame.size.width; CGFloat height = frame.size.height; _descriptionLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, width/3, height)]; _descriptionLabel.textAlignment = NSTextAlignmentCenter; _descriptionLabel.backgroundColor = [UIColor grayColor]; _descriptionLabel.layer.cornerRadius=8; _descriptionLabel.layer.borderWidth=2; [self addSubview:_descriptionLabel]; _textField = [[UITextField alloc] initWithFrame:CGRectMake(width/3, 0, width-width/3, height)]; _textField.layer.borderWidth=2; _textField.layer.cornerRadius=8; // _textField.tag = 1001; _textField.delegate = self; _textField.borderStyle = UITextBorderStyleRoundedRect; [self addSubview:_textField]; [self setDescription:description]; } return self; } - (void)setDescription:(NSString *)description { _descriptionLabel.text = description; } - (NSString *)text { return _textField.text; } - (void)setText:(NSString *)text { _textField.text = text; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; }// called when 'return' key pressed. return NO to ignore. @end
封装Button
+ (UIButton *)buttonWithType:(UIButtonType)type frame:(CGRect)frame title:(NSString *)title target:(id)target action:(SEL)action borderwidth:(CGFloat)borderwidth cornerradius:(CGFloat)cornerradius alpha:(CGFloat)alpha backgroundColor:(UIColor*)color setTitleColor:(UIColor*)setTitleColor { UIButton *button = [UIButton buttonWithType:type]; button.frame = frame; [button setTitle:title forState:UIControlStateNormal]; [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; button.layer.borderWidth=1; button.layer.cornerRadius=8; button.alpha=alpha; button.backgroundColor=[UIColor whiteColor]; [button setTitleColor:[UIColor blackColor]forState:UIControlStateNormal]; return button; }
相关文章推荐
- Unity3D技术之游戏的登陆注册界面详解
- 使用战火引擎制作游戏登陆界面
- 游戏界面登陆效果优化
- 2.Animation的使用 - 创建一个可以自动切换界面的游戏登陆页面
- 青瓷引擎之纯JavaScript打造HTML5游戏第二弹——《跳跃的方块》Part 9(登陆等待&结算界面)
- 如何实现从登陆界面跳转到游戏大厅界面
- 在游戏中弹出GameCenter登陆界面
- 青瓷引擎之纯JavaScript打造HTML5游戏第二弹——《跳跃的方块》Part 8(登陆界面)
- X64 Linux 无法从本地字符界面登陆
- Win10系统怎么锁屏才能让别人找不到登陆界面?
- curl采集登陆后的界面 若文件压缩,则解压文件
- windows无法验证,点击登陆后又返回登陆界面
- <登陆-注册-详情界面-模拟购物车界面-模拟订单界面>-----3.商品列表界面
- QT中登陆界面的编写
- 【win7系统怎样进去登陆界面】
- java写一个登陆界面
- WindowsXP 登陆界面 如何从2000恢复成XP
- Qt 之 模仿 QQ登陆界面——旋转窗口篇
- 三消类游戏《万圣大作战》01:开始界面&创建精灵
- 跟着BOY学习开发cocos2d-x 游戏 实战篇(2)之 欢迎 界面编写