测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布最新发布 | 2014年12月 |
由 Marcio Klepacz 维护。
依赖于 | |
hpple | ~> 0.2 |
SDWebImage | ~> 3.7 |
提升 NSAttributedString 功能,从 HTML 转换到 attributed string 开始
要运行示例项目,首先克隆仓库,并在 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]];
SALAttributedStringExtentions 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。