grethi / CHGInputAccessoryView

MIT License
7 stars 1 forks source link

CHGInputAccessoryView

Version License Platform

Usage

Screenshot of example CHGInputAccessoryView

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

CHGInputAccessoryView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "CHGInputAccessoryView"

Usage

Prepare a UIView or UIViewController

At first you must prepare a UIView or a UIViewController to become a first responder and attach an input accessory view.

Make UIView/UIViewController property inputAccessoryView writeable:

@property (nonatomic, readwrite, retain) UIView *inputAccessoryView;

Make sure your UIView/UIViewController can become first responder:

- (BOOL)canBecomeFirstResponder
{
return YES;
}

Set up a CHGInputAccessoryView

Setting up a new CHGInputAccessoryView is as simple as setting up a UIToolbar.

// get an instance of CHGInputAccessoryView
CHGInputAccessoryView *accessoryView = [CHGInputAccessoryView inputAccessoryView];

// optionally define a delegate
accessoryView.inputAccessoryViewDelegate = self;

// create a CHGInputAccessoryViewItem
CHGInputAccessoryViewItem *trashItem = [CHGInputAccessoryViewItem buttonWithTitle:@"Trash"];

// attach accessory view items
accessoryView.items = @[ trashItem ];

// attach the accessory view
self.inputAccessoryView = accessoryView;

Items

CHGInputAccessoryView comes with some prebuild items:

Enable/Disable items

// enable item
[accessoryView enableItem:item];

// disable item
[accessoryView disableItemAtIndex:1];

Actions

To use the build-in delegates (didTapItem: and didTapItemAtIndex:) assign a CHGInputAccessoryViewDelegate.

accessoryView.inputAccessoryViewDelegate = self;

Add and remove items


- (void)setItems:(NSArray<CHGInputAccessoryViewItem *> *)items;
- (void)setItems:(NSArray<CHGInputAccessoryViewItem *> *)items animated:(BOOL)animated;

- (void)addItem:(CHGInputAccessoryViewItem *)item animated:(BOOL)animated;
- (void)addItem:(CHGInputAccessoryViewItem *)item atIndex:(NSUInteger)index animated:(BOOL)animated;

- (void)removeItem:(CHGInputAccessoryViewItem *)item animated:(BOOL)animated;;
- (void)removeItemAtIndex:(NSUInteger)index animated:(BOOL)animated;

Author

Christian Greth, greth.christian@googlemail.com

License

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