Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/MatejBalantic/MBAutoGrowingTextView
An auto-layout base UITextView subclass which automatically grows with user input and can be constrained by maximal and minimal height - all without a single line of code
https://github.com/MatejBalantic/MBAutoGrowingTextView
Last synced: 3 months ago
JSON representation
An auto-layout base UITextView subclass which automatically grows with user input and can be constrained by maximal and minimal height - all without a single line of code
- Host: GitHub
- URL: https://github.com/MatejBalantic/MBAutoGrowingTextView
- Owner: MatejBalantic
- License: mit
- Archived: true
- Created: 2014-05-16T08:35:08.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2019-10-21T14:14:26.000Z (about 5 years ago)
- Last Synced: 2024-07-19T13:46:16.878Z (4 months ago)
- Language: Objective-C
- Size: 27.3 KB
- Stars: 125
- Watchers: 5
- Forks: 26
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-ios - MBAutoGrowingTextView - An auto-layout base UITextView subclass which automatically grows with user input and can be constrained by maximal and minimal height - all without a single line of code. (UI / TextField & TextView)
- awesome-ios-star - MBAutoGrowingTextView - An auto-layout base UITextView subclass which automatically grows with user input and can be constrained by maximal and minimal height - all without a single line of code. (UI / TextField & TextView)
README
Deprecated
=====================
This library is no longer maintained and is deprecated. The repository might be removed at any point in the future.MBAutoGrowingTextView
=====================An auto-layout based light-weight UITextView subclass which automatically grows and shrinks based on the size of user input and can be constrained by maximal and minimal height - all without a single line of code.
Made primarily for use in Interface builder and only works with Auto layout.
## Quick background
Auto layout is a great way to design your interfaces in a modern iOS application. Certain functionality, however, sometimes can't be achived out-of-the-box. One such example is auto-growing/shrinking UITextView. The problem of this view is that is by default a scrollable view, which means that it's intristic size would not change based on the content. One way around it would be to simply make it unscrollable, however this prevents user to scroll up and down when such element reaches it's maximal height. Thus, MBAutoGrowingTextView was created to work around this problem.## Functionality
* Made for iOS 7, fully leveraging Interface builder and Auto layout.
* UITextView's height will automatically grow or shrink based on amount of text entered by user
* Maximal and minimal height of the UITextView can be defined from the interface builder
* When maximal height is reached, UITextView content becomes scrollable
* **Not a single line of code required** for complete functionality![Animated demo](https://raw.githubusercontent.com/MatejBalantic/MBDocs/master/MBAutoGrowingTextView/animated.gif)
## Installation
Installation should be done via Cocoa Pods.Install CocoaPods if you didn't yet:
```bash
sudo gem install cocoapods
pod setup
```Change to the directory of your Xcode project, and Create and Edit your ``Podfile`` and add following line
```
pod 'MBAutoGrowingTextView', '~> 0.1.0'
``````bash
pod install
```Open your project in Xcode from the .xcworkspace file (not the usual project file)
## Usage
Usage is extremly simple and intuitive if you know your way around Auto Layout. This class leverages Auto-Layout constraints, by changing "height" constraint when needed. It will detect any "height smaller than" or "height greater than" constraints and make sure they are considered when making calculations.1. **Add UITextView to your interface file** (storyboard or xib) and resize it to desired size.
![Step 1](https://raw.githubusercontent.com/MatejBalantic/MBDocs/master/MBAutoGrowingTextView/step1.png)2. Assign custom class to it (click the UITextView, open the right Utilities panel, select third tab (Identity inspector) and write MBAutoGrowingTextView into Custom class field).
![Step 2](https://raw.githubusercontent.com/MatejBalantic/MBDocs/master/MBAutoGrowingTextView/step2.png)3. **Define the auto-layout constraints** in your interface builder, **as you would normally do**.
![Step 3](https://raw.githubusercontent.com/MatejBalantic/MBDocs/master/MBAutoGrowingTextView/step3.png)4. To limit **maximal height**, add the height constant again (as you did above). Select newly added constant and change the Relation field to "Less than or equal".
![Step 4](https://raw.githubusercontent.com/MatejBalantic/MBDocs/master/MBAutoGrowingTextView/step4.png)5. To limit **minimal height**, repeat step 4 and select "Greater than or equal" in relation field