Latest 1.0.0
Homepage https://github.com/Food52/Garnish
License MIT
Platforms ios 9.0
Frameworks UIKit
Authors

Garnish

Version
License
Platform

What is Garnish?

Garnish is a UITextView subclass that replicates the text effects of emoji detection in Messages. This GarnishTextView is extensible with custom detectors that define detection behavior and highlight colors/fonts.

Garnish Example

Installation

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

pod "Garnish"

Example

To run the example project, clone the repo, and open the workspace in the Example directory.

This example detector finds "important" words (words ending with a !) in a body of text.

struct Detector: GarnishDetector {
    var animates: Bool {
        return true
    }

    var highlightFont: UIFont? {
        return UIFont.preferredFont(forTextStyle: .title)
    }

    var highlightColor: UIColor {
        return #colorLiteral(red: 0.9995060563, green: 0.4978743792, blue: 0, alpha: 1)
    }

    var attachmentType: GarnishType {
        return GarnishType("important")
    }

    func detect(in string: NSString) -> [NSRange] {
        let regex = try! NSRegularExpression(pattern: "\w*!", options: [])

        let matches = regex.matches(in: string as String, options: [], range: NSRange(location: 0, length: string.length)).map {$0.range}

        return matches
    }
}

class ViewController: UIViewController {

    @IBOutlet weak var textView: GarnishTextView!
    override func viewDidLoad() {
        textView.garnishTextStorage.detectors = [Detector()]
    }
}

GarnishType is a simple wrapper to differentiate different types of detected strings. This allows for different colors or effects to be applied. For example, one could create a hashtag detector and an emoji detector in the same text view. Each detector could provide different colors for each type.

Author

Mike Simons, [email protected]

License

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

Latest podspec

{
    "name": "Garnish",
    "version": "1.0.0",
    "summary": "UITextView that highlights text like Messages.app",
    "description": "Garnish is a UITextView subclass that replicates the text effects of emoji detection in Messages. GarnishTextView is extensible with custom detectors that define detection behavior and highlight colors/fonts.",
    "homepage": "https://github.com/Food52/Garnish",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Mike Simons": " [email protected]"
    },
    "source": {
        "git": "https://github.com/Food52/Garnish.git",
        "tag": "1.0.0"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "Garnish/Classes/**/*",
    "frameworks": "UIKit",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This