SALAttributedStringExtentions 0.1.1

SALAttributedStringExtentions 0.1.1

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最新发布2014年12月

Marcio Klepacz 维护。



 
依赖于
hpple~> 0.2
SDWebImage~> 3.7
 

提升 NSAttributedString 功能,从 HTML 转换到 attributed string 开始

  • 异步下载图片。
  • 添加占位符。
  • 自动调整图片大小以适应行。

性能

使用默认 API 转换

Without

使用 SALAttributedStringExtentions 转换

With the extentiosn

使用方法

要运行示例项目,首先克隆仓库,并在 Example 目录中运行 pod install

只需要创建一个新的对象并设置代理

SALAttributedStringExtensions *attributedStringExtended = [[SALAttributedStringExtensions alloc] init];
attributedStringExtended.delegate = self;    

NSAttributedString *attrString = [attributedStringExtended attributedStringFromHTML:HTML limitingImageHeight:300];

实现代理

#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];
}

其他选项

//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]];

要求

  • iOS7+

安装

未来目标

  • [x] 异步下载图片。
  • [x] 添加到 Cocoapod。
  • [x] 支持 Iframe。
  • [ ] 点击放大图片。
  • [ ] 支持表格。
  • [ ] 支持YouTube。
  • [ ] 单元测试覆盖率99%。
  • [ ] 移除第三方框架依赖。
  • [ ] 识别 data-image-width 和 height。

许可证

SALAttributedStringExtentions 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。