Get Updates By E-mail 

Article Written By:
Johann Dowa

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.


  •  
  •  
  •  
  •  
  •  

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

Comments