CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

QKForms 0.0.9

QKForms 0.0.9

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Eric Webster.




QKForms 0.0.9

  • By
  • Eric Webster

Automatically handles moving text fields and text views out of the way of the keyboard. Also handles expanding text views to fit their text. Device orientation agnostic.

QKForms in action!

Usage

Here is a step by step guide to using QKForms with interface builder. The demo these steps refer to is included in QKFormsDemo.

Step 1

Create a scroll view (or table view, or collection view) and add the QKFormsScrollView class to it.

Step 2

If you want a text view which expands and moves out of the way of the keyboard as you type, then add the QKAutoExpandingTextView class to your text view.

Step 3

Add any number of text fields, searchbars, all inside another view, whatever!

That's it!

Everything is handled automatically after you've designed your form. Any text view with the class QKAutoExpandingTextView will expand as you type:

and the class QKFormsScrollView handles moving its text fields and text views out of the way of the keyboard. It also handles hiding the keyboard whenever it receives a tap gesture.

Options

Each of QKFormsScrollView, QKFormsTableView and QKFormsCollectionView comes with the following interface:

// Options, which can be found in the QKFormsOptions class.
@property (nonatomic, readonly) QKFormsOptions *options;

// An optional property which will be sent the TouchUpInside event
// when return is pressed while editing the last field in the form.
// The options property returnShouldMoveToNextField must be set to YES in order
// to use this.
@property (nonatomic, weak) IBOutlet UIButton *submitButton;

// Navigates to the next field, based on vertical position.
- (IBAction)nextField;

// Navigates to the previous field, based on vertical position.
- (IBAction)previousField;

- (IBAction)dismissKeyboard;
- (void)dismissKeyboardWithCompletion:(void (^)(void))completion;

There are a few options that you may set through QKFormsOptions:

// Whether return navigates to the next field or not.
// Default: YES
@property (nonatomic, assign) BOOL returnShouldMoveToNextField;

// In text views, whether return should insert a newline character.
// This overrides returnShouldMoveToNextField for text views.
// Default: NO
@property (nonatomic, assign) BOOL returnShouldInsertNewline;

// The margin between the keyboard and the field being edited.
// Default: 20
@property (nonatomic, assign) CGFloat keyboardTopMargin;

// Whether the form view displays a shadow when its content overflows.
// In order for this to work, this view must have a superview with the same bounds.
// Default: YES
@property (nonatomic, assign) BOOL showsShadow;

// This will force the field to be pulled down towards the keyboard, even
// if it is already above the keyboard.
// Default: NO
@property (nonatomic, assign) BOOL shouldFocusFields;

QKForms provides a subclass of UITextView called QKAutoExpandingTextView which handles automatically expanding itself to fit the text its given. It can also have a maximum height set:

// If maxHeight is a number other than 0, this view will not expand beyond maxHeight.
@property (nonatomic, assign) CGFloat maxHeight;

Another useful view called QKPlaceholderTextView, which is a subclass of QKAutoExpandingTextView, allows for placeholder text to be set on a text view.