Latest 2.0.0
Homepage https://github.com/grethi/CHGInputAccessoryView
License MIT
Platforms ios 10.0, requires ARC
Frameworks UIKit
Authors

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:

  • a button with title

    [CHGInputAccessoryViewItem buttonWithTitle:@"my title"];
  • a button with image

    [CHGInputAccessoryViewItem buttonWithImage:[UIImage imageNamed:@"my_image"]];
  • a separator
    [CHGInputAccessoryViewItem separatorWithColor:[UIColor lightGrayColor] height:20.f]
  • a UITextField
    CHGInputAccessoryViewItemTextField *item = [CHGInputAccessoryViewItemTextField item];
    item.textField.placeholder = @"Enter your text";
  • a UITextView
    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.

  • a UISwith
    CHGInputAccessoryViewItemSwitch *item = [CHGInputAccessoryViewItemSwitch item];
    item.switchView.on = YES;
  • a UIProgressView
    The InputAccessoryView has a build-in UIProgressView.

    CHGInputAccessoryView *accessoryView = [CHGInputAccessoryView inputAccessoryView];
    accessoryView.progressView.progress = 0.5f;
  • a flexible or fixed space
    [CHGInputAccessoryViewItemTextField flexibleSpace];
    [CHGInputAccessoryViewItemTextField fixedSpace:25.f];

Enable/Disable items

// enable item
[accessoryView enableItem:item];

// disable item
[accessoryView disableItemAtIndex:1];

Actions

  • InputAccssoryViewDelegate

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

accessoryView.inputAccessoryViewDelegate = self;
  • Assign target and action

    item.target = self;
    item.action = @selector(didTapMyItem:);

    By setting the target the build in delegates will not be called for this item.

  • Assign action block
    item.actionOnTap = ^(CHGInputAccessoryViewItem *item){
    NSLog(@"Tapped my item...");
    };

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, [email protected]

License

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

Latest podspec

{
    "name": "CHGInputAccessoryView",
    "version": "2.0.0",
    "summary": "Simply build an inputAccessoryView to show above a keyboard.",
    "description": "This pod will help to build an inputAccessoryView as simple and fast as using a UIToolbar. The CHGInputAccessoryView is based on UIToolbar with all its advantages and comes with some prebuild items like a separator, a UITextField, a UITextView or flexible and fixed spaces.",
    "homepage": "https://github.com/grethi/CHGInputAccessoryView",
    "license": "MIT",
    "authors": {
        "Christian Greth": "[email protected]"
    },
    "source": {
        "git": "https://github.com/grethi/CHGInputAccessoryView.git",
        "tag": "2.0.0"
    },
    "platforms": {
        "ios": "10.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This