#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITextFieldDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
#import "AppDelegate.h"
@interface AppDelegate ()
#pragma 把我们要使用的控件定义为实例变量.
@property (nonatomic, retain)UITextField *userNameTF;
@property (nonatomic, retain)UITextField *keyTF;
@end
@implementation AppDelegate
#pragma 重写dealloc方法
- (void)dealloc{
[_keyTF release];
[_userNameTF release];
[_window release];
[super dealloc];
}
#pragma 实现UITextFieldDelegate里面的键盘回收方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
#pragma UI02 主讲内容:UITextField,UIButton,UITextFieldDelegate
#pragma 一.UITextField
#pragma 练习 (1).输入用户名
UITextField *userNameTF = [[UITextField alloc] initWithFrame:(CGRectMake(50, 50, 200, 30))];
userNameTF.placeholder = @"请输入用户名";
userNameTF.textColor = [UIColor blueColor];
userNameTF.borderStyle = UITextBorderStyleRoundedRect;
userNameTF.clearButtonMode = UITextFieldViewModeAlways;
userNameTF.delegate = self;
userNameTF.tag = 101;
[self.window addSubview:userNameTF];
[userNameTF release];
#pragma (2).输入密码
UITextField *keyTF = [[UITextField alloc] initWithFrame:(CGRectMake(50, 90, 200, 30))];
keyTF.placeholder = @"请输入密码";
keyTF.textColor = [UIColor blackColor];
keyTF.secureTextEntry = YES;
keyTF.keyboardType = UIKeyboardTypeNumberPad;
keyTF.borderStyle = UITextBorderStyleRoundedRect;
keyTF.clearButtonMode = UITextFieldViewModeAlways;
keyTF.delegate = self;
keyTF.tag = 102;
[self.window addSubview:keyTF];
[keyTF release];
#pragma 二. UIButton 按钮
UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeSystem];
loginButton.frame = CGRectMake(40, 210, 30, 20);
[loginButton setTitle:@"xxx" forState:UIControlStateHighlighted];
[loginButton addTarget:self action:@selector(loginAction:) forControlEvents:(UIControlEventTouchUpInside)];
UIImage *image = [UIImage imageNamed:@"EG$Z4XLKDA01CBH5R1`@]}4"];
[loginButton setBackgroundImage:image forState:UIControlStateNormal];
[self.window addSubview:loginButton];
#pragma 找回密码
UIButton *getKeyButton = [UIButton buttonWithType:UIButtonTypeSystem];
getKeyButton.frame = CGRectMake(100, 200, 80, 44);
[getKeyButton setTitle:@"找回密码" forState:UIControlStateNormal];
[getKeyButton addTarget:self action:@selector(getKeyAction:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:getKeyButton];
#pragma 注册
UIButton *registrationButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
registrationButton.frame = CGRectMake(180, 210, 30, 20);
[registrationButton setTitle:@"注册" forState:UIControlStateNormal];
[registrationButton addTarget:self action:@selector(registrationAction:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:registrationButton];
UIImage *image2 = [UIImage imageNamed:@"/Users/lanou/Desktop/9ZDCZFDD5H3%5NX36(`][EU.jpg"];
[registrationButton setBackgroundImage:image2 forState:UIControlStateNormal];
#pragma 三. UITextFieldDelegate协议
UITextField *textField2 = [[UITextField alloc] initWithFrame:(CGRectMake(100, 300, 200, 30))];
textField2.placeholder = @"回收键盘";
textField2.borderStyle = UITextBorderStyleRoundedRect;
textField2.delegate = self;
[self.window addSubview:textField2];
[textField2 release];
return YES;
}
- (void)loginAction:(UIButton *)button{
[button removeTarget:self action:@selector(loginAction:) forControlEvents:UIControlEventTouchUpInside];
NSLog(@"进行安全判定, 然后进入登陆页面");
}
- (void)getKeyAction:(UIButton *)button{
[button removeTarget:self action:@selector(getKeyAction:) forControlEvents:UIControlEventTouchUpInside];
NSLog(@"找回密码");
}
- (void)registrationAction:(UIButton *)button{
[button removeTarget:self action:@selector(registrationAction:) forControlEvents:UIControlEventTouchUpOutside];
NSLog(@"注册");
}
@end