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

A UITextView subclass that adds support for changing dinamically the height in base of the text.
Also it has multiline placeholder thansk 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, '8.0'
use_frameworks!

target '<Your Target Name>' do
pod 'CGMessageTextView', '~> 0.1.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.1.0

Requirements

  • iOS 8.0+
  • Xcode 8.0+
  • Swift 3.0+

License

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

Latest podspec

{
    "name": "CGMessageTextView",
    "version": "0.1.1",
    "summary": "A UITextView subclass that adds support for changing dinamically the height in base of the text.",
    "description": "A UITextView subclass that adds support for changing dinamically the height in base of the text. Also it has multiline placeholder thansk 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": "work@carmelogallo.com"
    },
    "source": {
        "git": "https://github.com/cikpis/CGMessageTextView.git",
        "tag": "0.1.1"
    },
    "social_media_url": "https://twitter.com/cikpis",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "CGMessageTextView/Classes/**/*",
    "frameworks": "UIKit",
    "requires_arc": true,
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This