Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hsusmita/GrowingTextViewHandler-objc
https://github.com/hsusmita/GrowingTextViewHandler-objc
Last synced: about 2 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/hsusmita/GrowingTextViewHandler-objc
- Owner: hsusmita
- License: mit
- Created: 2015-03-13T06:43:08.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-08-04T12:38:12.000Z (over 9 years ago)
- Last Synced: 2024-10-11T20:34:28.707Z (about 1 month ago)
- Language: Objective-C
- Size: 308 KB
- Stars: 58
- Watchers: 6
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: license.txt
Awesome Lists containing this project
README
# GrowingTextViewHandler
An NSObject subclass to handle resizing of UITextView as the user types in. The textview resizes as long as the number of lines lies between specified minimum and maximum number of lines.
These are the public properties which can be set from the client code.
* animationDuration : Default 0.7
* maximumNumberOfLines : Default INT_MAX
* minimumNumberOfLines : Default 1#Installation
Add following lines in your pod file
pod 'GrowingTextViewHandler', '~> 1.0.3'
#Usage
First create an instance of GrowingTextViewHandler. It takes an UITextView and its height constraint as arguments. You can specify the maximum and minimum number of lines. Then in the method "textViewDidChange" call the method resizeTextView
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightConstraint;
@property (strong, nonatomic) GrowingTextViewHandler *handler;@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.handler = [[GrowingTextViewHandler alloc]initWithTextView:self.textView withHeightConstraint:self.heightConstraint];
[self.handler updateMinimumNumberOfLines:3 andMaximumNumberOfLine:8];
}- (void)textViewDidChange:(UITextView *)textView {
[self.handler resizeTextViewWithAnimation:YES];
}
@endHowever when you set text programmatically, **- (void)textViewDidChange:(UITextView *)textView** does not get called. For this case you can resize UITextView as follows:
[self.handler setText: @"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
withAnimation:YES];
# Screenshots