Latest 0.1.2
Homepage https://github.com/DynamicSignal/ios-twitter-text-counter
License MIT
Platforms ios 8.0
Authors

iOS Twitter Text Counter

Version
License
Platform

This custom UIControl resembles Twitter’s new progress based web UI that represents the number of characters left. It also handles highlighting any extra characters in your UITextView.

Screenshot

Here’s an animated screenshot to show you an idea of how it works.

ScreenShot

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

You should install twitter-text and use it to parse your string then pass your weightedLength to the control.

Installation

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

pod 'VSTwitterTextCounter'

Manual:

  1. In your Xcode Project, take VSTwitterCounter.swift from VSTwitterTextCounter folder and drag them into your project.

  2. Start using this new UIControl Subclass!

SDK Support

It supports iOS 8.0 to iOS 11.0
Live rendering in Interface builder will require Xcode 6.x

Usage

Creating your filter

By Code

Somewhere, for example in your viewDidLoad, alloc and init the filter UIControl:

let twitterTextCounter = VSTwitterTextCounter()

This initializes our Twitter Text Counter using default size and max characters count to 280.

Note that the size of the control is predefined and should not be changed. Use __CONTROL_SIZE__ static property for reference.

Adding to your UIView:

view.addSubview(twitterTextCounter)

Then, after your text gets updated, most probably in:-

func textViewDidChange(_ textView: UITextView)

You will need to parse the text using Twitter’s TwitterTextParser SDK, which should look like that:-

let weightedLength = TwitterTextParser.defaultParser().parseTweet(textView.text).weightedLength

You will need to update your text length by calling:-

twitterTextCounter.update(with: textView, textWeightedLength: weightedLength)

Note: textView will be needed in order for the control to update the highlighted state of any overflowing text.

Via Interface builder

Add a new UIView to your xib, and update its class to VSTwitterTextCounter.
Enjoy ;)

Configuration

Counter

Property Effect Default value
Max Count Sets the max value for weightedLength DEFAULT_MAX_COUNT / 280
Weighted Length Current text weight 0

Author

Shady Elyaski, sh[email protected]

License

This Code is released under the MIT License by Dynamic Signal

PS. We are hiring, check out our hiring page.

http://dynamicsignal.com

Latest podspec

{
    "name": "VSTwitterTextCounter",
    "version": "0.1.2",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "platforms": {
        "ios": "8.0"
    },
    "authors": {
        "Shady Elyaski": "[email protected]"
    },
    "screenshots": "https://raw.github.com/DynamicSignal/ios-twitter-text-counter/master/Example/Assets/sample.gif",
    "homepage": "https://github.com/DynamicSignal/ios-twitter-text-counter",
    "summary": "Twitter's new progress based web UI.",
    "description": "This custom UIControl resembles Twitter's new progress based web UI that represents the number of characters left. It also handles highlighting any extra characters in your UITextView.",
    "source": {
        "git": "https://github.com/DynamicSignal/ios-twitter-text-counter.git",
        "tag": "0.1.2"
    },
    "social_media_url": "https://twitter.com/ShadyElyaski",
    "source_files": "VSTwitterTextCounter/Classes/**/*",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This