标签:
#import "AppDelegate.h"
@interface AppDelegate ()<UITextFieldDelegate>
@end
@implementation AppDelegate
/*
回收键盘的步骤
1、遵守UITextFieldDelegate协议
2、创建UITextField对象
3、设置UITextField对象的delegate属性为AppDelegate
4、实现UITextFieldDelegate的textFieldShouldReturn:方法
5、在textFieldShouldReturn:方法取消textField作为第一响应者
*/
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//创建一个UIWindow对象
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
//创建一个UITextField对象
UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 100, 30)];
text.backgroundColor = [UIColor redColor];
[self.window addSubview:text];
text.delegate = self;
return YES;
}
//实现textFieldDelegate的textFieldShouldReturn:方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
标签:
原文地址:http://www.cnblogs.com/chen-en-ni66/p/4903048.html