gro

GrowingTextViewHandler

Showing:

Popularity

Downloads/wk

0

GitHub Stars

59

Maintenance

Last Commit

6yrs ago

Contributors

0

Package

Dependencies

0

License

MIT

Categories

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 ()<UITextViewDelegate>

  @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];
  }
 @end

However 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

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100