#import "AppDelegate.h"
#import "LoginViewController.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]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
// ***登陆界面***
//创建 LoginViewController 对象
LoginViewController *disembark = [[LoginViewController alloc]init];
// 设置为 window 的根视图控制器
self.window.rootViewController = disembark;
//释放
[disembark release];
[self.window makeKeyAndVisible];
return YES;
}
#import "LoginViewController.h"
@interface LoginViewController ()
@end
@implementation LoginViewController
- (void)loadView {
LoginView *passwordView = [[LoginView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
self.view = passwordView;
[passwordView release];
}
- (BOOL)textFieldShouldReturn:(UITextField *)namelabel {
//
[((LoginView *)self.view).passwordLT.textField becomeFirstResponder];
// [namelabel resignFirstResponder];
// [((LoginView *)self.view).namelabel.textField becomeFirstResponder];
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
// 登陆界面 属性设置
// 用户名 UILabel 和输入框 UITextField
((LoginView *)self.view).namelabel.label.text = @"用户名:";
((LoginView *)self.view).namelabel.label.textColor = [UIColor redColor];
((LoginView *)self.view).namelabel.label.font = [UIFont fontWithName:@"AmericanTypewriter-Bold" size:22];
((LoginView *)self.view).namelabel.label.textAlignment = NSTextAlignmentCenter;
((LoginView *)self.view).namelabel.textField.placeholder = @"☆请输入用户名★";
((LoginView *)self.view).namelabel.textField.clearButtonMode = UITextFieldViewModeAlways;
((LoginView *)self.view).namelabel.textField.delegate = self;
// 密码 UILabel 和 输入框 UITextField
((LoginView *)self.view).passwordLT.label.text = @"密码:";
// 字体颜色
((LoginView *)self.view).passwordLT.label.textColor = [UIColor redColor];
// 显示 字体与大小
((LoginView *)self.view).passwordLT.label.font = [UIFont fontWithName:@"Helvetica-Bold" size:22];
((LoginView *)self.view).passwordLT.label.textAlignment = NSTextAlignmentCenter;
// 密码输入后显示圆点
((LoginView *)self.view).passwordLT.textField.secureTextEntry = YES;
// 把键盘右下角的 return 键 改成 “GO”
((LoginView *)self.view).passwordLT.textField.returnKeyType = UIReturnKeyGo;
// 输入框右侧设置快速删除功能
((LoginView *)self.view).passwordLT.textField.clearButtonMode = UITextFieldViewModeAlways;
((LoginView *)self.view).passwordLT.textField.placeholder = @"☆请输入密码★";
((LoginView *)self.view).passwordLT.textField.delegate = self;
// 设置属性
((LoginView *)self.view).logButton.backgroundColor = [UIColor brownColor];
[((LoginView *)self.view).logButton setTitle:@"登陆" forState:(UIControlStateNormal)];
[((LoginView *)self.view).logButton setTitle:@"☺☺☺" forState:(UIControlStateHighlighted)];
[((LoginView *)self.view).logButton setTitle:@"◕‿◕" forState:(UIControlStateSelected)];
// 点击 登陆 按钮 功能
[((LoginView *)self.view).logButton addTarget:self action:@selector(B1count:) forControlEvents:UIControlEventTouchUpInside];
// 设置属性
((LoginView *)self.view).findlButton.backgroundColor = [UIColor brownColor];
[((LoginView *)self.view).findlButton setTitle:@"密码找回" forState:(UIControlStateNormal)];
[((LoginView *)self.view).findlButton setTitle:@"☺☺☺" forState:(UIControlStateHighlighted)];
[((LoginView *)self.view).findlButton setTitle:@"◕‿◕" forState:(UIControlStateSelected)];
// 点击 密码找回 按钮 功能
[((LoginView *)self.view).findlButton addTarget:self action:@selector(B2count:) forControlEvents:UIControlEventTouchUpInside];
// 设置属性
((LoginView *)self.view).loginButton.backgroundColor = [UIColor brownColor];
[((LoginView *)self.view).loginButton setTitle:@"注册" forState:(UIControlStateNormal)];
[((LoginView *)self.view).loginButton setTitle:@"☺☺☺" forState:(UIControlStateHighlighted)];
[((LoginView *)self.view).loginButton setTitle:@"◕‿◕" forState:(UIControlStateSelected)];
// 点击 注册 按钮 功能
[((LoginView *)self.view).loginButton addTarget:self action:@selector(B3count:) forControlEvents:UIControlEventTouchUpInside];
// 点击键盘上的 return 按钮时,收回键盘。
((LoginView *)self.view).namelabel.textField.delegate = self;
}
- (void)B1count:(UIButton *)b1count
{
if ([((LoginView *)self.view).namelabel.textField.text isEqualToString:@"123"] && [((LoginView *)self.view).passwordLT.textField.text isEqualToString:@"123"] ) {
UIAlertView *TS1 = [[UIAlertView alloc]initWithTitle:@"提示" message:@"欢迎回来" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[TS1 show];
NSLog(@"登陆成功!");
}else {
UIAlertView *TS2 = [[UIAlertView alloc]initWithTitle:@"提示" message:@"用户名或密码错误,请核对后再试" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[TS2 show];
NSLog(@"登陆失败!");
}
b1count.selected = !b1count.selected;
[b1count resignFirstResponder];
[self.view endEditing:YES];
}
- (void)B2count:(UIButton *)b2count
{
NSLog(@"进入找回密码界面");
b2count.selected = !b2count.selected;
[b2count resignFirstResponder];
[self.view endEditing:YES];
}
- (void)B3count:(UIButton *)b3count
{
NSLog(@"进入注册界面");
b3count.selected = !b3count.selected;
[b3count resignFirstResponder];
[self.view endEditing:YES];
}
#import <UIKit/UIKit.h>
#import "LTView.h"
@interface LoginView : UIView
@property(nonatomic,retain,readonly)LTView *namelabel; //用户名输入框
@property(nonatomic,retain,readonly)LTView *passwordLT; //密码输入框
@property(nonatomic,retain,readonly)UIButton *logButton; //登陆按钮
@property(nonatomic,retain,readonly)UIButton *findlButton; //找回密码按钮
@property(nonatomic,retain,readonly)UIButton *loginButton; //注册按钮
@end
#import "LoginView.h"
@implementation LoginView
- (void)dealloc
{
[_namelabel release];
[_passwordLT release];
[super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
UIImage *temp = [UIImage imageNamed:@"10.JPG"];
UIImageView *temp2 = [[UIImageView alloc]initWithImage:temp];
temp2.frame = [[UIScreen mainScreen]bounds];
[self addSubview:temp2];
// 用户名 UILabel 和输入框 UITextField
_namelabel = [[LTView alloc]initWithFrame:CGRectMake(40, 100, 290, 40)];
[self addSubview:_namelabel];
// 密码 UILabel 和 输入框 UITextField
_passwordLT = [[LTView alloc]initWithFrame:CGRectMake(40, 150, 290, 40)];
[self addSubview:_passwordLT];
// 登陆按钮
_logButton = [UIButton buttonWithType:UIButtonTypeCustom];
_logButton.frame = CGRectMake(40, 230, 80, 40);
[_logButton setTitle:@"登陆" forState:UIControlStateNormal];
[self addSubview:_logButton];
// 密码找回按钮
_findlButton = [UIButton buttonWithType:UIButtonTypeCustom];
_findlButton.frame = CGRectMake(150, 230, 80, 40);
[_findlButton setTitle:@"密码找回" forState:UIControlStateNormal];
[self addSubview:_findlButton];
// 注册按钮
_loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
_loginButton.frame = CGRectMake(260, 230, 80, 40);
[_loginButton setTitle:@"注册" forState:UIControlStateNormal];
[self addSubview:_loginButton];
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end
#import <UIKit/UIKit.h>
@interface LTView : UIView
@property(nonatomic,retain,readonly)UILabel *label;
@property(nonatomic,retain,readonly)UITextField *textField;
@end
#import "LTView.h"
@implementation LTView
- (void)dealloc {
[_label release];
[_textField release];
[super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// CGFloat x = frame.origin.x;
// CGFloat y = frame.origin.y;
CGFloat width = frame.size.width;
CGFloat height = frame.size.height;
_label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, width / 3, height)];
[self addSubview:_label];
_textField = [[UITextField alloc]initWithFrame:CGRectMake(width / 3, 0, width * 2 / 3, height)];
_textField.borderStyle = UITextBorderStyleRoundedRect;
[self addSubview:_textField];
}
return self;
}
- (void)setkeyboardType:(UIKeyboardType)keyboardType
{
}