ASJExpandableTextView 0.5

ASJExpandableTextView 0.5

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Jan 2022

Maintained by Sudeep.



  • By
  • Sudeep

ASJExpandableTextView

UITextView's most obvious omission is the ability to set placeholder text. This class fixes that and provides more. You can make the text view expand and contract according to its content and have a "Done" button over the keyboard to hide it.

alt tag

Installation

CocoaPods is the preferred way to install this library. Add this command to your Podfile:

pod 'ASJExpandableTextView'

Usage

Creating an ASJExpandableTextView is easy. It has a simple interface consisting of four properties which are IBInspectable. This means that they can be set using the interface builder of your choice; xibs or storyboards.

@property (nullable, copy, nonatomic) IBInspectable NSString *placeholder;

Sets the placeholder. Visible when there is nothing typed in the text view.

@property (nullable, strong, nonatomic) IBInspectable UIColor *placeholderTextColor;

Sets the placeholder text color. Will work only when the placeholder is visible.

@property (assign, nonatomic) CGFloat lineSpacing;

Sets the spacing between two lines of text.

@property (assign, nonatomic) IBInspectable BOOL isExpandable;

Set this to make the text view expand and contract according to its content.

@property (assign, nonatomic) IBInspectable NSUInteger maximumLineCount;

You can set the number of visible lines of the text view. Default is 4. To use this property, isExpandable must be set to YES.

@property (assign, nonatomic) IBInspectable BOOL shouldShowDoneButtonOverKeyboard;

The "return" key on the keyboard for a UITextView brings a new line, unlike a UITextField where the keyboard gets hidden. Set this property to show a "Done" button over the keyboard which can hide the keyboard.

@property (assign, nonatomic) BOOL placeholderUsesFullViewHeight;

Determines whether the placeholder view is spread over the whole text view or is shown at the top left corner like usual. Details to NO.

@property (nullable, copy) DoneTappedBlock doneTappedBlock;

You can handle the event of the keyboard getting hidden using this block. To use this property, shouldShowDoneButtonOverKeyboard must be set to YES.

alt tag

You can create one using just the interface builder, drop in a UITextView and change the class to ASJExpandableTextView.

alt tag

Credits

  • To Abhijit Kayande for fixing the choppy animation
  • To devxoul for placeholder label position fix
  • To Daleijn for adding new placeholder property

License

ASJExpandableTextView is available under the MIT license. See the LICENSE file for more info.