This library is a singleton, once it takes effect, any interface of the whole project will be effective. The code to make it work can be written anywhere, I wrote it in AppDelegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
manager.enable = YES;
manager.shouldResignOnTouchOutside = YES;
manager.shouldToolbarUsesTextFieldTintColor = YES;
manager.enableAutoToolbar = NO;
return YES;
}
enable controls whether the entire function is enabled.
shouldResignOnTouchOutside controls whether clicking on the background hides the keyboard.
shouldToolbarUsesTextFieldTintColor Controls whether the toolbar text color on the keyboard is user-defined.
enableAutoToolbar controls whether to display the toolbar on the keyboard.
The above settings enable this library.
How to use, the code is as follows:
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, strong) IQKeyboardReturnKeyHandler *returnKeyHandler;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.returnKeyHandler = [[IQKeyboardReturnKeyHandler alloc] initWithViewController:self];
self.returnKeyHandler.lastTextFieldReturnKeyType = UIReturnKeyDone;
self.returnKeyHandler.toolbarManageBehaviour = IQAutoToolbarBySubviews;
}
- (void)dealloc
{
self.returnKeyHandler = nil;
}
@end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
manager.enable = YES;
manager.shouldResignOnTouchOutside = YES;
manager.shouldToolbarUsesTextFieldTintColor = YES;
manager.enableAutoToolbar = NO;
return YES;
}
enable controls whether the entire function is enabled.
shouldResignOnTouchOutside controls whether clicking on the background hides the keyboard.
shouldToolbarUsesTextFieldTintColor Controls whether the toolbar text color on the keyboard is user-defined.
enableAutoToolbar controls whether to display the toolbar on the keyboard.
The above settings enable this library.
How to use, the code is as follows:
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, strong) IQKeyboardReturnKeyHandler *returnKeyHandler;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.returnKeyHandler = [[IQKeyboardReturnKeyHandler alloc] initWithViewController:self];
self.returnKeyHandler.lastTextFieldReturnKeyType = UIReturnKeyDone;
self.returnKeyHandler.toolbarManageBehaviour = IQAutoToolbarBySubviews;
}
- (void)dealloc
{
self.returnKeyHandler = nil;
}
@end