AutoLayoutTextViews subclasses UITextView and adds placeholder text, auto resizing, and keyboard avoiding functionality.
AutoLayoutTextViews was inspired in part by Mouhcine El Amine's work on EAMTextView and by Matej Balantič's work on MBAutoGrowingTextView.
The easiest way to add AutoLayoutTextViews to your project is using CocoaPods. Simply add the following to your Podfile:
pod 'AutoLayoutTextViews', '~> 1.0'
Then run pod install as you normally would.
Alternatively, you can manually include AutoLayoutTextViews in your project by doing the following:
-
Clone this repo locally onto your computer, or press
Download ZIPto simply download the latestmastercommit. -
Drag the
AutoLayoutTextViewsfolder into your project, making sureCopy items into destination group's folder (if needed)is checked.
AutoLayoutTextViews is architected as follows:
-
ALPlaceholderTextViewsubclassesUITextViewand adds an optionalplaceholderproperty. -
ALAutoResizingTextViewsubclassesALPlaceholderTextView, which gives it aplaceholderproperty, and adds "auto resizing" behavior- the text view will grow and shrink as the user types.
Note: when you create layout constraints (either in Interface Builder or in code), make sure that you set the height and/or bottom constraints to greater than or equal. See the AutoLayoutTextViewsDemo project for an example of how to do this using Interface Builder.
ALKeyboardAvoidingTextViewalso subclassesALPlaceholderTextView, which gives it aplaceholderproperty, and adds "keyboard avoiding" behavior- the text view's frame will shrink/expand as the keyboard will show/hide.
Simply use ALPlaceholderTextView, ALAutoResizingTextView, or ALKeyboardAvoidingTextView as a replacement for a UITextView where you the added functionality provided by one of these.
For example usage of each of these, see the AutoLayoutTextViewsDemo project within this repository.
Note: AutoLayoutTextViewsDemo uses CocoaPods to add AutoLayoutTextViews as a dependency. So, you will need to first run pod install in the AutoLayoutTextViewsDemo directory.
Patches and feature additions are welcome!
To contribute:
- Open a new issue and propose your change- before writing code- to make sure the open source community agrees it's needed.
Make sure to include your rationale for why this change is needed (especially for new method/feature additions).
-
Fork this repo.
-
Make your changes.
-
Write unit tests for your changes (as needed). If possible, a TDD approach is best!
If you've never written unit tests before, that's okay!
You can learn by checking out Jon Reid's (@qcoding) excellent website, including a section just about unit testing.
- Write in-line documentation comments for your property/method additions.
This project is part of the CocoaPods specs repo, which includes appledoc-parsed documentation hosted for each pod on CocoaDocs.
If you're not familar with appledoc, check out Mattt Thompson's (@matt) introductory post about it.
-
Submit a pull request, referencing your original issue from (1) above.
-
Last but not least, sit back and enjoy your awesomeness in helping make your fellow developers' lives a bit easier!
Like EAMTextView and MBAutoGrowingTextView, AutoLayoutTextViews is released under the MIT license. See the LICENSE file for more details.