Latest 0.1.3
License MIT
Platforms ios 8.0

iOS Twitter Text Counter


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.


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



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


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


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

pod 'VSTwitterTextCounter'


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

  2. Start using this new UIControl Subclass!

Supported Swift Versions:

Library Version Supported Swift Version
0.1.3 and above Swift 5
0.1.2 Swift 3

SDK Support

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


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:


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 ;)



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


Shady Elyaski, sh[email protected]


This Code is released under the MIT License by Dynamic Signal

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

Latest podspec

    "name": "VSTwitterTextCounter",
    "version": "0.1.3",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "platforms": {
        "ios": "8.0"
    "swift_version": "5.0",
    "authors": {
        "Shady Elyaski": "[email protected]"
    "screenshots": "",
    "homepage": "",
    "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": "",
        "tag": "0.1.3"
    "social_media_url": "",
    "source_files": "VSTwitterTextCounter/Classes/**/*"

Pin It on Pinterest

Share This