Latest 0.3.0
License MIT
Platforms ios 8.0, requires ARC

[![CI Status]( Solniczek/StringInChain.svg?style=flat)]( Solniczek/StringInChain)

An convenient and fast approach to create AttributedString.

StringInChain give you a far more clean way to create attributed string.

The Old Way

With the old way, create am attributed string is dirty and complex.

let baseString: NSString = "String In Chain"
var attrText = NSMutableAttributedString(string: baseString as String)
attrText.addAttribute(NSForegroundColorAttributeName, value: UIColor.blueColor(), range: baseString.rangeOfString("String"))
attrText.addAttribute(NSFontAttributeName, value: UIFont(name: "Avenir", size: 30.0)!, range: baseString.rangeOfString("String"))
attrText.addAttribute(NSUnderlineStyleAttributeName, value: 1, range: baseString.rangeOfString("In"))
attrText.addAttribute(NSUnderlineColorAttributeName, value: UIColor.yellowColor(), range: baseString.rangeOfString("In"))
attrText.addAttribute(NSStrokeWidthAttributeName, value: 1, range: baseString.rangeOfString("Chain"))
attrText.addAttribute(NSStrokeColorAttributeName, value: UIColor.blackColor(), range: baseString.rangeOfString("Chain"))
label.attributedText = attrText

With StringInChain

let baseString = "String In Chain"
var attrText = baseString.chain { (string) -> Void in
    string.match("String").withColor(UIColor.blueColor()).withFont(UIFont(name: "Avenir", size: 30.0)!)
    string.match("In").underline(1, andColor: UIColor.yellowColor())
    string.match("Chain").withStroke(1, andColor: UIColor.blackColor())
label.attributedText = attrText.attrString

Instead of match(text: String) (this way you can find only first occurance of string), you can use:

match(from: Int, to:Int)


string.match(from: 7, to: 10).withColor(UIColor.blueColor()).withFont(UIFont(name: "Avenir", size: 30.0)!)

This way you can create AttributedString by match range from and to

If you want, there is also fast, inline way to make AttributedString

label.attributedText = "String In Chain".match("String").withColor(UIColor.blueColor()).withFont(UIFont(name: "Avenir", size: 30.0)!).attrString

Clean and Easy, don’t You think?



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



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

pod "StringInChain"


Lukasz Solniczek, l.solniczek(at)gmail(dot)com


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

Latest podspec

    "name": "StringInChain",
    "version": "0.3.0",
    "summary": "StringInChain give you a far more clean way to create attributed string.",
    "description": "                        An convenient and fast approach to create AttributedString.n                        StringInChain give you a far more clean way to create attributed string.n",
    "homepage": "",
    "license": "MIT",
    "authors": {
        "Lukasz Solniczek": "l.solniczek[email protected]"
    "source": {
        "git": "",
        "tag": "0.3.0"
    "platforms": {
        "ios": "8.0"
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "StringInChain": [

Pin It on Pinterest

Share This