Code Monkey home page Code Monkey logo

chginputaccessoryview's Introduction

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:

  • 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.

chginputaccessoryview's People

Contributors

grethi avatar

Watchers

Vu Duc Nhuan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.