/JPAttributedStringBuilder

An easier way to work with NSAttributedStrings

Primary LanguageObjective-CMIT LicenseMIT

JPAttributedStringBuilder

A DSL for creating NSStrings and NSAttributedStrings

[ ![Build Status] travis-image ] travis [ ![Version] cocoa-version ] cocoadocs [ ![Platform] cocoa-plaform ] cocoadocs

Installation

Install with CocoaPods:

pod 'JPAttributedStringBuilder'

Usage

NSAttributedString Creation

Have you ever had to append a bunch of NSAttributedStrings?

NSMutableAttributedString *text = [[NSMutableAttributedString alloc] init];

[text appendAttributedString:
     [[NSAttributedString alloc] initWithString:firstName
                                     attributes:@{
                                                  NSFontAttributeName : [UIFont boldSystemFont:12.0f],
                                                  NSForegroundColorAttributeName : [UIColor blackColor]
                                                  }]];

[text appendAttributedString:
     [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n", self.search.neighborhoodsString]
                                     attributes:@{
                                                  NSFontAttributeName : [UIFont proximaNovaBoldWithSize:16.0f],
                                                  NSForegroundColorAttributeName : [UIColor ucDarkColor]
                                                  }]];

[text appendAttributedString:
     [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@", self.bedPriceString]
                                     attributes:@{
                                                  NSFontAttributeName : [UIFont proximaNovaRegularWithSize:14.0f],
                                                  NSForegroundColorAttributeName : [UIColor ucDarkColor]
                                                  }]];

Is this better?

JPAttributedStringBuilder *stringBuilder = [[JPAttributedStringBuilder alloc] init];
stringBuilder.font = [UIFont systemFontOfSize:14.f];
stringBuilder.foregroundColor = [UIColor redColor];
stringBuilder.backgroundColor = [UIColor lightGrayColor];
stringBuilder.text = @"This is a better string";

NSAttributedString *jpAttributedString = [stringBuilder build];

Examples

There is an example included with the project. To install,

$ pod install
$ open ZipLocateSample.xcworkspace/

##Contribute

Send me pull requests!

##Authors

James Paolantonio - @jpaolantonio

####Extra

Let me know if you are using this or want anything changed!! :)