YTPAccessoryInputView 1.1.2

YTPAccessoryInputView 1.1.2

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Jan 2017

Maintained by Karl Pan.



  • By
  • carlpan

Easy way to add accessory input view to custom input tool bar.

Introduction

Typically in chat page or comment page of the app, you will need to attach an input tool bar to the bottom of the view. This input tool bar will contain a textfield and a button. Sometimes you will find writing chat messages or comments not enough, you will probably want to send stickers, payments, contact info, location info, etc. The easiest way you would do is to add an extra button to the input tool bar and connect it to an action sheet. With this category, you can do more than that, just design an input view and tell the ViewController your input view.

Demo

Installation

YTPAccessoryInputView requires iOS 10.0 or later.

Example

Imagine you already connected your input tool bar, input tool bar button, and the bottom layout constraint.

@property (weak, nonatomic) IBOutlet UIView *chatInputToolBar;  // Your tool bar 
@property (weak, nonatomic) IBOutlet UIButton *chatInputToolBarButton;  // Button in your tool bar to bring accessory input view up
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint;  // Constraint from input tool bar to the bottom of the view

Now tell your view controller the custom input view you want to use.

UIView *inputView = [[[NSBundle mainBundle] loadNibNamed:@"YourInputView" owner:self options:nil] firstObject];
self.accessoryInputView = inputView;

self.inputToolBar = self.chatInputToolBar;
self.inputToolBarBottomSpace = self.bottomConstraint;

Then configure your input view with following call

[self ytp_configureAccessoryInputView];

Next step is to connect the button to trigger your custom input view. In the IBAction of your button, add following

[self ytp_toggleAccessoryInputViewWithButton:self.chatInputToolBarButton];

If you want dissmiss keyboard or your custom accessory input view, for example

[self ytp_dismissKeyboardOrAccessoryInputView];

Finally, you need to call the clean up method which dismisses keyboard observers. The ideal place to put it is in viewDidDisappear.

[self ytp_resetViewControllerStatus];

That's it!!

Author

carlpan, [email protected]

License

YTPAccessoryInputView is available under the MIT license. See the LICENSE file for more info.