📱Easy custom placeholder and growing (iMessage-like) UITextView with customisation
You can easily adjust the color, font, and position of the placeholder. The height of the textview automatically changes every time you increase or decrease the line in the textview. You can specify a maxHeight property so the textview can start to scroll.
- iOS 9.0 or newer
- Swift 4.2
RSTextViewMaster is available through CocoaPods.
pod 'RSTextViewMaster'
import RSTextViewMaster
For the moment, please use textView.setText(text: String)
to update textview's text. By using .text
settler, the placeholder won't be removed. This will get fixed in future updates.
isAnimate: Bool = true
maxLength: Int = 0
minHeight: CGFloat = 0
maxHeight: CGFloat = 0
placeHolder: String = ""
placeHolderFont: UIFont = UIFont.systemFont(ofSize: 17)
placeHolderColor: UIColor = UIColor(white: 0.8, alpha: 1.0)
placeHolderTopPadding: CGFloat = 0
placeHolderBottomPadding: CGFloat = 0
placeHolderRightPadding: CGFloat = 5
placeHolderLeftPadding: CGFloat = 5
let textViewMaster = RSTextViewMaster()
textViewMaster.delegate = self
inputView.addSubview(textViewMaster)
You will have to set constrains by code if you take this approach.
- TextView Set class to "RSTextViewMaster".
- Set delegate to it's view controller
- Set a height constraint but check "remove at runtime". This way Xcode won't bother you and the textview will work like magic
Check the demo for an example.
RSTextViewMaster inherits from UITextViewDelegate. You can also use UITextViewDelegate by default. Added or modified functions
func growingTextView(growingTextView: RSTextViewMaster, shouldChangeTextInRange range:NSRange, replacementText text:String) -> Bool
func growingTextViewShouldReturn(growingTextView: RSTextViewMaster)
func growingTextView(growingTextView: RSTextViewMaster, willChangeHeight height:CGFloat)
func growingTextView(growingTextView: RSTextViewMaster, didChangeHeight height:CGFloat)
RSTextViewMaster is based on JeaSungLEE's work
RSTextViewMaster is available under the GNU license.