在AppDelegate.h中将FirstViewController设置为根视图控制器
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"1"]];
_window.backgroundColor = color;
[_window makeKeyAndVisible];
_window.rootViewController = [[FirstViewController alloc] autorelease];
return YES;
}
创建几个类
"FirstViewController.h"
"ScendViewController.h"
"ThirdViewController.h"
在FirstViewController中定义两个输入框用来输入QQ和密码
宏定义视图的宽和高
#define KScreen [UIScreen mainScreen].bounds.size.width
#define KScreenH [UIScreen mainScreen].bounds.size.height
- (void)viewDidLoad {
[super viewDidLoad];
//设置背景颜色
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreen, KScreenH)];
view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"1"]];
[self.view addSubview:view];
// QQ空间图标
UIImageView *imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake((KScreen - 180)/2, 20, 180, 170)];
imgView1.image = [UIImage imageNamed:@"bg_login_logo@2x"];
[self.view addSubview:imgView1];
// QQ空间
UIImageView *imgView2 = [[UIImageView alloc] initWithFrame:CGRectMake((KScreen - 180)/2, 200, 180, 60)];
imgView2.image = [UIImage imageNamed:@"bg_login_qzone@2x"];
[self.view addSubview:imgView2];
// QQ输入框
_textFlield1 = [[UITextField alloc] initWithFrame:CGRectMake(40, 280, 300, 50)];
_textFlield1.background = [UIImage imageNamed:@"btn_login_top@2x"];
// QQ输入框点击事件
[_textFlield1 addTarget:self action:@selector(textAction:) forControlEvents:UIControlEventEditingDidBegin];
// 水印
_textFlield1.placeholder = @" QQ号";
// 编辑时可以清除输入的数字
_textFlield1.clearButtonMode = UITextFieldViewModeWhileEditing;
[self.view addSubview:_textFlield1];
// 密码输入框
_textFlield2 = [[UITextField alloc] initWithFrame:CGRectMake(40, 331, 300, 50)];
_textFlield2.background = [UIImage imageNamed:@"btn_login_bottom@2x"];
// 密码输入框点击事件
[_textFlield2 addTarget:self action:@selector(textAction:) forControlEvents:UIControlEventEditingDidBegin];
_textFlield2.placeholder = @" 密码";
_textFlield2.clearButtonMode = UITextFieldViewModeWhileEditing;
[self.view addSubview:_textFlield2];
// 登陆按钮
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button1.frame = CGRectMake(40, 400, 300, 50);
// 设置按钮圆角
button1.layer.cornerRadius = 5;
button1.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"2"]];
[button1 setTitle:@"登陆" forState:UIControlStateNormal];
[button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.view addSubview:button1];
// 注册帐号按钮
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button2.frame = CGRectMake(280, 550, 60, 50);
[button2 setTitle:@"注册帐号" forState:UIControlStateNormal];
[button2 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
// 按钮点击事件
[button2 addTarget:self action:@selector(button2Action:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button2];
_textFlield1.delegate = self;
_textFlield2.delegate = self;
}
- (void)getQQNum:(NSString *)num withPassWord:(NSString *)pass{
_textFlield1.text = num;
_textFlield2.text = pass;
}
//跳转到另一个页面
- (void)textAction:(UITextField *)text{
ThirdViewController *thirdViewCtrl = [[ThirdViewController alloc] init];
// thirdViewCtrl.delegate = self;
[self presentViewController:thirdViewCtrl animated:YES completion:nil];
[thirdViewCtrl release];
}
//跳转到另一个页面
- (void)button2Action:(UIButton *)button{
ScendViewController *scendViewCtrl = [[ScendViewController alloc] init];
[self presentViewController:scendViewCtrl animated:YES completion:nil];
[scendViewCtrl release];
}
@property (assign,nonatomic) id<GetMessageProtocol>delegate;
@property (retain,nonatomic) UITextField *textFlield1;
@property (retain,nonatomic) UITextField *textFlield2;
- (void)viewDidLoad {
[super viewDidLoad];
// 设置视图控制器颜色
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"camera_bg_iphone5"]];
// 背景颜色
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 100, KScreenW, KScreenH)];
view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"1"]];
[self.view addSubview:view];
// QQ号标签
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 120, 60, 40)];
label1.text = @"QQ号";
[self.view addSubview:label1];
// 密码标签
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(20, 180, 60, 40)];
label2.text = @"密码";
[self.view addSubview:label2];
// QQ输入框
_textFlield1 = [[UITextField alloc] initWithFrame:CGRectMake(80, 120, 280, 40)];
_textFlield1.borderStyle = UITextBorderStyleRoundedRect;
// _textFlield1.text = _str1;
_textFlield1.clearButtonMode = UITextFieldViewModeWhileEditing;
[self.view addSubview:_textFlield1];
// 密码输入框
_textFlield2 = [[UITextField alloc] initWithFrame:CGRectMake(80, 180, 280, 40)];
_textFlield2.borderStyle = UITextBorderStyleRoundedRect;
// _textFlield2.text = _str2;
_textFlield2.secureTextEntry = YES;
_textFlield2.clearButtonMode = UITextFieldViewModeWhileEditing;
[self.view addSubview:_textFlield2];
// 注册按钮
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button1.frame = CGRectMake(20, 250, 340, 50);
button1.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"2"]];
[button1 setTitle:@"注册" forState:UIControlStateNormal];
[button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// 注册按钮点击事件
[button1 addTarget:self action:@selector(button1Action:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1];
// 关闭按钮
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button2.frame = CGRectMake(310, 50, 60, 50);
[button2 setTitle:@"关闭" forState:UIControlStateNormal];
[button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// 关闭按钮事件
[button2 addTarget:self action:@selector(button2Action:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button2];
}
//跳回第一个页面
- (void)button1Action:(UIButton *)button{
// 单例
// ScendViewController *s = [[ScendViewController alloc] init];
// s.str1 = _textFlield1.text;
// s.str2 = _textFlield2.text;
//代理
if ([self.delegate respondsToSelector:@selector(getQQNum:withPassWord:)]) {
[self.delegate getQQNum:_textFlield1.text withPassWord:_textFlield2.text];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)button2Action:(UIButton *)button{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
// 背景颜色
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH)];
view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"1"]];
[self.view addSubview:view];
// QQ空间图标
UIImageView *imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(30, 30, 60, 60)];
imgView1.image = [UIImage imageNamed:@"bg_login_logo@2x"];
[self.view addSubview:imgView1];
// QQ空间
UIImageView *imgView2 = [[UIImageView alloc] initWithFrame:CGRectMake(100, 50, 130, 40)];
imgView2.image = [UIImage imageNamed:@"bg_login_qzone@2x"];
[self.view addSubview:imgView2];
// QQ输入框
UITextField *textFlield1 = [[UITextField alloc] initWithFrame:CGRectMake(20, 110, 300, 50)];
textFlield1.background = [UIImage imageNamed:@"btn_login_top@2x"];
textFlield1.placeholder = @" QQ号";
[textFlield1 becomeFirstResponder];
textFlield1.clearButtonMode = UITextFieldViewModeWhileEditing;
[self.view addSubview:textFlield1];
// 密码输入框
UITextField *textFlield2 = [[UITextField alloc] initWithFrame:CGRectMake(20, 161, 300, 50)];
textFlield2.background = [UIImage imageNamed:@"btn_login_bottom@2x"];
textFlield2.placeholder = @" 密码";
textFlield2.secureTextEntry = YES;
textFlield2.clearButtonMode = UITextFieldViewModeWhileEditing;
[self.view addSubview:textFlield2];
// 登陆按钮
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button1.frame = CGRectMake(20, 230, 300, 50);
button1.layer.cornerRadius = 5;
button1.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"2"]];
[button1 setTitle:@"登陆" forState:UIControlStateNormal];
[button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button1 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1];
}
//跳回第一个页面
- (void)buttonAction:(UIButton *)button{
FirstViewController *firstViewCtrl = [[FirstViewController alloc] init];
firstViewCtrl.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:firstViewCtrl animated:YES completion:nil];
}