#import "IQKeyboardManager.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
// 控制整个功能是否启用。
manager.enable = YES;
// 点击屏幕隐藏键盘
manager.shouldResignOnTouchOutside = YES;
// 键盘覆盖输入框时候页面自动上移
// manager.keyboardDistanceFromTextField = 100;
// 控制键盘上的工具条文字颜色是否用户自定义
manager.shouldToolbarUsesTextFieldTintColor = YES;
// 为键盘添加工具栏
manager.enableAutoToolbar = YES;
// 最新版的设置键盘的returnKey的关键字 ,可以点击键盘上的next键,自动跳转到下一个输入框,最后一个输入框点击完成,自动收起键盘。
manager.toolbarManageBehaviour = IQAutoToolbarByTag;
[self.window makeKeyAndVisible];
return YES;
}
框架的启用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[IQKeyboardManager sharedManager] setEnable:YES];
[[IQKeyboardManager sharedManager] setEnableAutoToolbar:YES];
return YES;
}
enable控制整个功能是否启用。
shouldResignOnTouchOutside控制点击背景是否收起键盘。
shouldToolbarUsesTextFieldTintColor 控制键盘上的工具条文字颜色是否用户自定义。
enableAutoToolbar控制是否显示键盘上的工具条。
以上设置,就启用了这个库。
有时想在某个界面启用,可以在
- (void)viewWillAppear:(BOOL)animated 和 - (void)viewWillDisappear:(BOOL)animated
里面进行开启关闭
manager.toolbarDoneBarButtonItemText = @"1234";
或者
manager.toolbarDoneBarButtonItemImage = [UIImageimageNamed:@"IQKeyboardManagerScreenshot"];
manager.shouldToolbarUsesTextFieldTintColor = NO;
manager.toolbarTintColor = [UIColor redColor];
manager.shouldShowTextFieldPlaceholder = YES;
manager.placeholderFont = [UIFont systemFontOfSize:14.0];
manager.keyboardDistanceFromTextField = 10.0f;
manager.preventShowingBottomBlankSpace = NO;
- (void)textFieldDidEndEditing:(UITextField *)textField