Latest 0.0.1
Homepage https://github.com/cruffenach/CREasyStyleTextStorage
License MIT
Platforms ios 7.0, requires ARC
Frameworks UIKit

CREasyStyleTextStorage

CREasyStyleTextStorage is a NSTextStorage subclass that provides a convenient way to apply distinct styles to substrings. There is a demo project showing a general use case for it. PR’s and Issues welcome. Lots more functionality to come.

Basic Usage

CREasyStyleTextStorage allows for specific strings to have unique styling. Configuring and using in a UITextView would look something like this.

CREasyStyleTextStorage *textStorage = [[CREasyStyleTextStorage alloc] init];

// Set default attributes

[textStorage setDefaultAttributes:@{NSFontAttributeName             : [UIFont systemFontOfSize:14],
                                    NSForegroundColorAttributeName  : [UIColor blackColor]}];

// Make '@' symbols red

[textStorage setAttributes:@{NSForegroundColorAttributeName : [UIColor redColor]} 
                 forString:@"@"];

// Make '#' symbols green

[textStorage setAttributes:@{NSForegroundColorAttributeName : [UIColor greenColor]} 
                 forString:@"#"];

NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
[textStorage addLayoutManager:layoutManager];
NSTextContainer *container = [[NSTextContainer alloc] initWithSize:self.view.bounds.size];
[layoutManager addTextContainer:container];

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectZero textContainer:container];
[self.view addSubview:textView];

Latest podspec

{
    "name": "CREasyStyleTextStorage",
    "version": "0.0.1",
    "license": "MIT",
    "summary": "NSTextStore subclass for easy text styling",
    "description": "CREasyStyleTextStorage is a concrete NSTextStore subclass that allows for fast exact string match styling.",
    "homepage": "https://github.com/cruffenach/CREasyStyleTextStorage",
    "authors": "Collin Ruffenach",
    "source": {
        "git": "https://github.com/cruffenach/CREasyStyleTextStorage.git",
        "tag": "0.0.1"
    },
    "platforms": {
        "ios": "7.0"
    },
    "source_files": "CREasyStyleTextStorage",
    "frameworks": "UIKit",
    "requires_arc": true
}

Pin It on Pinterest

Share This