03
//加载根视图的方法,我们通常在这个方法中,指定根视图为我们想要的某个视图
//并且在一个视图控制器的生命周期,此方法只会走一次。
//在加载方法中,不能使用self.view这个getter方法获取根视图,因为此时根视图正在加载,并没有真实存在。
- (void)loadView {
//创建loginView
_loginView = [[LoginView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//将loginView指定为self.view
self.view = _loginView;
// [self.view addSubview:_loginView];
//为输入框设置代理
_loginView.userNameLTV.textField.delegate = self;
// _loginView.passwordLTV.textField.delegate = self;
//为button添加点击事件
[_loginView.loginButton addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
[_loginView.registButton addTarget:self action:@selector(regist) forControlEvents:UIControlEventTouchUpInside];
[_loginView.getbackButton addTarget:self action:@selector(getback) forControlEvents:UIControlEventTouchUpInside];
}
- (void)login {
NSLog(@"登录成功");
[_loginView.userNameLTV.textField resignFirstResponder];
[_loginView.passwordLTV.textField resignFirstResponder];
}
- (void)regist {
NSLog(@"注册");
[_loginView.userNameLTV.textField resignFirstResponder];
[_loginView.passwordLTV.textField resignFirstResponder];
//创建注册页面的视图控制器对象
RegistViewController *registVC = [[RegistViewController alloc] init];
//模态推出新的视图控制器
[self presentViewController:registVC animated:YES completion:nil];
[registVC release];
}
- (void)getback {
NSLog(@"找回密码");
[_loginView.userNameLTV.textField resignFirstResponder];
[_loginView.passwordLTV.textField resignFirstResponder];
}
//视图控制器自带的根视图加载完毕的方法,默认根视图是空白视图,并且背景色是透明色。
//如果想要显示内容,只需要在此方法内部创建视图,并且添加到根视图上面。
- (void)viewDidLoad {
[super viewDidLoad];
//先修改视图的背景颜色
self.view.backgroundColor = [UIColor redColor];
self.view.alpha = 0.3;
/*
CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width;
//创建一个自定义视图LTView
LTView *userNameLTV = [[LTView alloc] initWithFrame:CGRectMake(30, 80, screenWidth - 60, 40) text:@"用户名:" textColor:[UIColor blackColor] font:[UIFont boldSystemFontOfSize:18] borderStyle:UITextBorderStyleRoundedRect placeholder:@"请输入用户名" secureTextEntry:NO keyboardType:UIKeyboardTypeDefault];
userNameLTV.textField.delegate = self;
[self.view addSubview:userNameLTV];
[userNameLTV release];
LTView *passwordLTV = [[LTView alloc] initWithFrame:CGRectMake(30, 150, screenWidth - 60, 40) text:@"密 码:" textColor:[UIColor blackColor] font:[UIFont boldSystemFontOfSize:18] borderStyle:UITextBorderStyleRoundedRect placeholder:@"请输入密码" secureTextEntry:YES keyboardType:UIKeyboardTypeDefault];
passwordLTV.textField.delegate = self;
[self.view addSubview:passwordLTV];
[passwordLTV release];*/
}