CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.
TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | May 2017 |
Maintained by Christian Greth.
To run the example project, clone the repo, and run pod install
from the Example directory first.
CHGInputAccessoryView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "CHGInputAccessoryView"
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;
}
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;
CHGInputAccessoryView comes with some prebuild items:
[CHGInputAccessoryViewItem buttonWithTitle:@"my title"];
[CHGInputAccessoryViewItem buttonWithImage:[UIImage imageNamed:@"my_image"]];
[CHGInputAccessoryViewItem separatorWithColor:[UIColor lightGrayColor] height:20.f]
CHGInputAccessoryViewItemTextField *item = [CHGInputAccessoryViewItemTextField item];
item.textField.placeholder = @"Enter your text";
CHGInputAccessoryViewItemTextField *item = [CHGInputAccessoryViewItemTextField item];
item.textField.placeholder = @"Enter your text";
Tip: Modify the textField or textView by accessing CHGInputAccessoryViewItemTextField/TextView property textField/textView. The textField/textView will automatically resize to the maximum availabe width. The textView also resizes automatically to maximum available height. If you want a fixed size for your textField/textView assign a frame on it and set the CHGInputAccessoryViewItem property flexibleSize to NO.
CHGInputAccessoryViewItemSwitch *item = [CHGInputAccessoryViewItemSwitch item];
item.switchView.on = YES;
CHGInputAccessoryView *accessoryView = [CHGInputAccessoryView inputAccessoryView];
accessoryView.progressView.progress = 0.5f;
[CHGInputAccessoryViewItemTextField flexibleSpace];
[CHGInputAccessoryViewItemTextField fixedSpace:25.f];
// enable item
[accessoryView enableItem:item];
// disable item
[accessoryView disableItemAtIndex:1];
To use the build-in delegates (didTapItem: and didTapItemAtIndex:) assign a CHGInputAccessoryViewDelegate.
accessoryView.inputAccessoryViewDelegate = self;
item.target = self;
item.action = @selector(didTapMyItem:);
By setting the target the build in delegates will not be called for this item.
item.actionOnTap = ^(CHGInputAccessoryViewItem *item){
NSLog(@"Tapped my item...");
};
- (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;
Christian Greth, [email protected]
CHGInputAccessoryView is available under the MIT license. See the LICENSE file for more info.