SALAttributedStringExtentions

Improves NSAttributedString functionalities, starting with the convertion from HTML to attributed string

  • Asynchrounsly download images.
  • Adds placeholder.
  • Auto Resize image to fit in line.

[![CI Status](http://img.shields.io/travis/Marcio Klepacz/SALAttributedStringExtentions.svg?style=flat)](https://travis-ci.org/Marcio Klepacz/SALAttributedStringExtentions) Version License Platform

Performance

###Converting using the default API Without

###Converting using SALAttributedStringExtentions
With the extentiosn

Usage

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

Just need to create a new object and set the delegate:

SALAttributedStringExtensions *attributedStringExtended = [[SALAttributedStringExtensions alloc] init];
attributedStringExtended.delegate = self;    
            
NSAttributedString *attrString = [attributedStringExtended attributedStringFromHTML:HTML limitingImageHeight:300];

Implementing the delegates:

#pragma mark - SALAttributedStringDelegate
- (UIImage *)imagePlaceholder
{
    return [UIImage imageNamed:@"your-image-placeholder-name"];
}
                      
- (void)textAttachmentDownloaded:(SALResizableTextAttachment *)textAttachment inRange:(NSRange)range
{
    // Just add the textAttachment on your textStorage
    [self.textView.textStorage addAttribute:NSAttachmentAttributeName value:textAttachment range:range];
}

Other options:

//Creating without passing a limit height
NSAttributedString *attrString = [attributedStringExtended attributedStringFromHTML:HTML];
                                
//Creating with a custom textAttachment background color
NSAttributedString *attrString = [attributedStringExtended attributedStringFromHTML:HTML withTextAttachmentBackgroundColor:[UIColor blackColor]];

Requirements

  • iOS7 +

Installation

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

pod "SALAttributedStringExtentions"

The horizon

  • Download images asynchonously.
  • Add to Cocoapod.
  • Iframe support.
  • Tap to enlarge images.
  • Table support.
  • Youtube support.
  • 99% Unit test coverage
  • Remove third party framewroks dependency.
  • Recoginize data-image-width,height.

License

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