Library Providing Easily Customizable HTML-Style Syntax For Rich Text With NSAttributedString

Previously I mentioned a very cool library allowing you to make rich text using an HTML/CSS style syntax.

There’s a number of similar libraries out there, and today I came across another very cool library called Slash by Chris Devereux that provides a simple HTML style markup language for NSAttributedString.

The difference with this library and others is that it takes advantage of new features for NSAttributedString in iOS6 and you can easily define your own customizations using a dictionary.

Here’s an example from the readme showing how you can customize the different tags:

NSDictionary *style = @{
    @"$default" : @{NSFontAttributeName  : [UIFont fontWithName:@"HelveticaNeue" size:14]},
    @"strong"   : @{NSFontAttributeName  : [UIFont fontWithName:@"HelveticaNeue-Bold" size:14]},
    @"em"       : @{NSFontAttributeName  : [UIFont fontWithName:@"HelveticaNeue-Italic" size:14]},
    @"h1"       : @{NSFontAttributeName  : [UIFont fontWithName:@"HelveticaNeue-Medium" size:48]},
    @"h2"       : @{NSFontAttributeName  : [UIFont fontWithName:@"HelveticaNeue-Medium" size:36]},
    @"h3"       : @{NSFontAttributeName  : [UIFont fontWithName:@"HelveticaNeue-Medium" size:32]},
    @"h4"       : @{NSFontAttributeName  : [UIFont fontWithName:@"HelveticaNeue-Medium" size:24]},
    @"h5"       : @{NSFontAttributeName  : [UIFont fontWithName:@"HelveticaNeue-Medium" size:18]},
    @"h6"       : @{NSFontAttributeName  : [UIFont fontWithName:@"HelveticaNeue-Medium" size:16]}
};

NSAttributedString *myAttributedString = [SLSMarkupParser attributedStringWithMarkup:markup style:style error:NULL];

Here’s an image from the example app showing a few of the different tags in action:

Slash

You can find Slash on Github here.

A very nice library for easily creating customized rich text.

Original article: Library Providing Easily Customizable HTML-Style Syntax For Rich Text With NSAttributedString

©2012 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.

Leave a Reply

Your email address will not be published. Required fields are marked *