ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - KennethTsang/GrowingTextView: An UITextView in Swift. Support auto growing, placeholder and length limit.
An UITextView in Swift. Support auto growing, placeholder and length limit. - KennethTsang/GrowingTextView
Visit Site

GitHub - KennethTsang/GrowingTextView: An UITextView in Swift. Support auto growing, placeholder and length limit.

GitHub - KennethTsang/GrowingTextView: An UITextView in Swift. Support auto growing, placeholder and length limit.

GrowingTextView

Version License Platform Language Language Language Language

Requirements

iOS 8.0 or above

Installation

CocoaPods

GrowingTextView is available through CocoaPods. To install it, simply add the following line to your Podfile:

Swift 5.0

pod 'GrowingTextView', '0.7.2'

Swift 4.2

pod 'GrowingTextView', '0.6.1'

Swift 4.1

pod 'GrowingTextView', '~> 0.5'

Swift 3

pod 'GrowingTextView', '~> 0.4'

Swift 2.3 (Stopped update since Sep 2016)

pod 'GrowingTextView', :git => 'https://github.com/KennethTsang/GrowingTextView.git', :branch => 'swift2'

Carthage

GrowingTextView is also available through Carthage. To install it, add the following line to your Cartfile:

Swift 5.0

github "KennethTsang/GrowingTextView" ~> 0.7

Swift 4.2

github "KennethTsang/GrowingTextView" ~> 0.6

Swift 4.1

github "KennethTsang/GrowingTextView" ~> 0.5

Swift 3

github "KennethTsang/GrowingTextView" ~> 0.4

Swift 2.3 (Stopped update since Sep 2016)

github "KennethTsang/GrowingTextView" "swift2"

Manually

Copy GrowingTextView.swift into your project.

Usage

Example

GrowingTextview is just a textview, download the example to see how to use it as a input toolbar like other instant messaging apps.

Using GrowingTextview programmatically

let textView = GrowingTextView()
textView.delegate = self
addSubview(textView)

Using GrowingTextview in Storyboard

  1. Drag a TextView into Storyboard.
  2. Set class to "GrowingTextView".
  3. Set delegate to it's view controller.
automaticallyAdjustsScrollViewInsets

Sometime the view controller may incorrectly adjust the inset of textview automatically. To avoid this, set automaticallyAdjustsScrollViewInsets to false

override func viewDidLoad() {
	super.viewDidLoad()
	automaticallyAdjustsScrollViewInsets = false
}

Customization

Parameter Type Description Default
maxLength Int Maximum text length. Exceeded text will be trimmed. 0 means no limit. 0
trimWhiteSpaceWhenEndEditing Bool Trim white space and new line characters when textview did end editing. true
placeholder String? Placeholder text. nil
placeholderColor UIColor Placeholder text color. UIColor(white: 0.8, alpha: 1.0)
attributedPlaceholder NSAttributedString? Attributed Placeholder text. nil
minHeight CGFloat Minimum height of textview. 0.0
maxHeight CGFloat Maximum height of textview. 0.0

Examples

textView.maxLength = 140
textView.trimWhiteSpaceWhenEndEditing = false
textView.placeholder = "Say something..."
textView.placeholderColor = UIColor(white: 0.8, alpha: 1.0)
textView.minHeight = 25.0
textView.maxHeight = 70.0
textView.backgroundColor = UIColor.whiteColor()
textView.layer.cornerRadius = 4.0

Animation

  1. Adopt GrowingTextViewDelegate instead of UITextViewDelegate.
  2. Implement textViewDidChangeHeight.
  3. Call layoutIfNeeded() on superview inside the animation.
class ViewController: UIViewController, GrowingTextViewDelegate {
	func textViewDidChangeHeight(_ textView: GrowingTextView, height: CGFloat) {
	   UIView.animate(withDuration: 0.2) {
	       self.view.layoutIfNeeded()
	   }
	}
}

Delegate

GrowingTextViewDelegate is inherited from UITextViewDelegate. You may use it's delegate function as a normal UITextView.

class ViewController: UIViewController, GrowingTextViewDelegate {
    func textViewDidChange(_ textView: UITextView) {
    	...
    }
    func textViewDidEndEditing(_ textView: UITextView) {
    	...
    }
}

Check out UITextViewDelegate here: https://developer.apple.com/reference/uikit/uitextviewdelegate

Author

Kenneth Tsang, [email protected]

License

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

More Resources
to explore the angular.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory