How to hide Toolbar in IQKeyboardManager iOS Swift 3

匿名 (未验证) 提交于 2019-12-03 08:48:34

问题:

I'm using the IQKeyboardManger library to scroll text fields when started typing using the keyboard, but I don't want to display the default toolbar from their library. Below is the code I've used.

override func viewDidLoad() {         super.viewDidLoad()          self.chatTextField.inputAccessoryView = [[UIView alloc] init];  //This will remove toolbar which have done button.          self.chatTextField.keyboardDistanceFromTextField = 8; //This will modify default distance between textField and keyboard. For exact value, please manually check how far your textField from the bottom of the page. Mine was 8pt.          } 

回答1:

You can set IQKeyboardManager below properties.

I assume you have enabled the IQKeyboardManager in didFinishLaunch of app delegate like this

    IQKeyboardManager.sharedManager().enable = true 

shouldShowTextFieldPlaceholder to false ==> If you want to hide placeholder toolbar section

shouldHidePreviousNext to false ==> If you want to hide next and prev button and so on.

You can enable the settings in didFinishLaunch of AppDelegate like this

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {     // Override point for customization after application launch.      IQKeyboardManager.sharedManager().enable = true      IQKeyboardManager.sharedManager().enableAutoToolbar = false     IQKeyboardManager.sharedManager().shouldShowTextFieldPlaceholder = false     IQKeyboardManager.sharedManager().shouldHidePreviousNext = false       return true } 


回答2:

You can enable or disable the toolbar in didFinishLaunchingWithOptions of AppDelegate:

IQKeyboardManager.sharedManager().enable = true  IQKeyboardManager.sharedManager.enableAutoToolbar = false 

For more info see Properties and functions usage



回答3:

Swift 3 You must use shouldResignOnTouchOutside to resign textField if touched outside of UITextField/UITextView.

Add this in your ViewController if you want it in an specific ViewController or to override all your application in the file AppDelegate.

Inside the method:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {   IQKeyboardManager.sharedManager().enable = true   IQKeyboardManager.sharedManager().enableAutoToolbar = false   IQKeyboardManager.sharedManager().shouldShowToolbarPlaceholder = false   IQKeyboardManager.sharedManager().shouldResignOnTouchOutside = true } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!