Latest 0.2.1
Homepage https://github.com/cikpis/CGMessageTextView
License MIT
Platforms ios 10.1, requires ARC
Frameworks UIKit
Authors

A UITextView subclass that adds support for changing dynamically the height in base of the text.
Also it has multiline placeholder thanks to https://github.com/MoZhouqi/KMPlaceholderTextView.
All is written in Swift and it use AutoLayout.

Usage

You can set one of the following values:

placeholderText
placeholderTextColor
placeholderFont
placeholderTextAlignment

In order to change dinamically the heigh, use one of the follow delegates:

func contentSizeDidChange(withContentSize contentSize: CGSize)
func contentSizeWidthDidChange(withWidth width: CGFloat)
func contentSizeDeltaWidthDidChange(withDelta delta: CGFloat)
func contentSizeHeightDidChange(withHeight height: CGFloat)
func contentSizeDeltaHeightDidChange(withDelta delta: CGFloat)

If you want to know if the text changed, just use the follow delegate

func textDidChange(withText text: String)

Code

Initialization

let messageTextView = CGMessageTextView()
messageTextView.messageTextViewDelegate = self
messageTextView.placeholderText = "Write something..."
addSubview(messageTextView)

Delegates ( all are optional )

extension MyClass: CGMessageTextViewDelegate {
    func contentSizeDidChange(withContentSize contentSize: CGSize) { }
    func contentSizeWidthDidChange(withWidth width: CGFloat) { }
    func contentSizeDeltaWidthDidChange(withDelta delta: CGFloat) { }
    func contentSizeHeightDidChange(withHeight height: CGFloat) { }
    func contentSizeDeltaHeightDidChange(withDelta delta: CGFloat) { }
}

Installation

CocoaPods

You can install the latest release version of CocoaPods with the following command:

$ gem install cocoapods

Simply add the following line to your Podfile:

platform :ios, '10.1'
use_frameworks!

target '<Your Target Name>' do
pod 'CGMessageTextView', '~> 0.2.0'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate CGMessageTextView into your Xcode project using Carthage, specify it in your Cartfile:

github "cikpis/CGMessageTextView" ~> 0.2.0

Requirements

  • iOS 10.1+
  • Xcode 10+
  • Swift 4.2+

License

CGMessageTextView is released under the MIT license. See LICENSE for details.

Latest podspec

{
    "name": "CGMessageTextView",
    "version": "0.2.1",
    "summary": "A UITextView subclass that adds support for changing dynamically the height in base of the text.",
    "description": "A UITextView subclass that adds support for changing dynamically the height in base of the text. Also it has multiline placeholder thanks to https://github.com/MoZhouqi/KMPlaceholderTextView. All is written in Swift and it use AutoLayout.",
    "homepage": "https://github.com/cikpis/CGMessageTextView",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Carmelo Gallo": "[email protected]gallo.com"
    },
    "source": {
        "git": "https://github.com/cikpis/CGMessageTextView.git",
        "tag": "0.2.1"
    },
    "social_media_url": "https://twitter.com/cikpis",
    "platforms": {
        "ios": "10.1"
    },
    "source_files": "CGMessageTextView/Classes/**/*",
    "frameworks": "UIKit",
    "requires_arc": true,
    "swift_version": "4.2"
}

Pin It on Pinterest

Share This