DCTextEngine 0.1.0

DCTextEngine 0.1.0

测试已测试
语言语言 Obj-CObjective C
许可证 Apache 2
发布上次发布2014 年 12 月

Dalton Cherry 维护。



  • 作者
  • Dalton Cherry

一个将文本转换为富文本字符串以及将富文本字符串转换为文本的引擎。默认支持 HTML 和 Markdown。它是 iOS 和 OSX 的跨平台引擎。

依赖

需要 CoreText。

示例

NSString *string = @"#Dalton Cherry\n##Dalton Cherry\n*Lorem Ipsum* is simply _dummy_ text of the **printing** and typesetting industry. Lorem Ipsum has been the industry's standard *dummy* text ever since the 1500s. Here is a link to test with [Google](http://www.google.com/), should work fine. Here is a raw link: https://github.com. Hello at @austin, here is that email [email protected]. youtube video: http://www.youtube.com/watch?v=XibDfYd83Zg here is more text. Some more text";

DCTextEngine *engine = [DCTextEngine engineWithMarkdown];
__weak blockEngine = engine;
[engine addPattern:@"more text." found:^DCTextOptions*(NSString *regex, NSString *text){
    DCTextOptions *opts = [DCTextOptions new];
    NSTextAttachment *attach = [[NSTextAttachment alloc] init];
    attach.image = [UIImage imageNamed:@"subways.png"];
    attach.bounds = CGRectMake(0, 0, self.view.frame.size.width, 100);
    opts.attachment = attach;
    return opts;
}];
[engine addPattern:@"(^|\\s)@\\w+" found:^DCTextOptions*(NSString *regex, NSString *text){
    DCTextOptions *opts = [DCTextOptions new];
    opts.color = [UIColor redColor];
    opts.font = [blockEngine boldFont];
    return opts;
}];

alt tag

注解

正如示例所示,该引擎具有非常强大的正则表达式解析能力,但仍然非常简单易用。这个引擎适用于 iOS 6,但您可应用的样式会非常有限。我 强烈 建议使用 iOS 7 或以上版本,或者至少 10.7 或以上版本。

联系方式

Dalton Cherry