美文网首页
支持选择复制的richlabel.

支持选择复制的richlabel.

作者: 就biu了 | 来源:发表于2017-09-26 18:03 被阅读106次

GRichLabel

https://github.com/GIKICoder/GRichLabel
A rich Label that supports selection, copying.

Simulator Screen Shot - iPhone 7 Plus - 2017-09-26 at 18.06.26.png

Features

1,基于coretext绘制文本.内部使用YYAsyncLayer提供异步绘制任务

2,支持选择/复制文本.

3,支持自定义表情排版

4,可自定义文本选择弹出menuView(暂未实现)

5,对于文本token 采用多模匹配算法. 详见GACAutomaton.文本匹配效率比系统字符串匹配效率提高百倍.

Usage

1

  GRichLabel *richLabel = [GRichLabel new];
  richLabel.frame = CGRectMake(5, 0, self.view.frame.size.width-10, 500);
  richLabel.text = @"xxxxxx";

2

{
self.tokens = @[@"@冯科",@"@王金yu",@"@巩柯",@"#郭天池#"];
GRichLabel *richLabel = [GRichLabel new];
richLabel.frame = CGRectMake(5, 0, self.view.frame.size.width-10, 500);
}

- (void)setRichText
{
    __weak typeof(self) ws = self;
    NSString* string =[self content1];
    __block NSMutableArray *tokens = [NSMutableArray array];
    [self.tokens enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (!obj) *stop = NO;
        GAttributedToken * token = [GAttributedToken attributedTextToken:obj];
        token.tokenClickBlock = ^(GAttributedToken *token) {
            [ws gotoVC:token.textToken];
        };
        [tokens addObject:token];
    }];
    GAttributedToken *regex = [GAttributedToken new];
    regex.regexToken = Phone;
    regex.tokenClickBlock = ^(GAttributedToken *token) {

    };
    GAttributedStringLayout *layout = [GAttributedStringLayout attributedLayout:string];
    layout.tokenPatternConfigs = tokens.copy;
    layout.regexPatternConifgs = @[regex];
    layout.textAlignment = kCTTextAlignmentJustified;
    layout.linespace = 1;
    layout.lineIndent = 2;
    layout.font = [UIFont systemFontOfSize:14];

    NSMutableAttributedString * truncation = [[NSMutableAttributedString alloc] initWithString:@"...全文"];

    layout.truncationToken = truncation;
    GDrawTextBuilder * builder = [GAttributedStringFactory createDrawTextBuilderWithLayout:layout boundSize:self.richLabel.frame.size];
    self.richLabel.textBuilder = builder;
  
}
  

Thanks

*YYText

相关文章

  • 支持选择复制的richlabel.

    GRichLabel https://github.com/GIKICoder/GRichLabelA rich ...

  • 在Tmux 中开启鼠标选择与复制

    在 tmux 2.1 中,开启鼠标支持,在.tmux中添加一行配置 复制 按住shift键,然后拖动鼠标复制要选择...

  • mysql binlog基本原理

    基于binlog的主从复制 Mysql 5.0以后,支持通过binary log(二进制日志)以支持主从复制。复制...

  • TextView支持长按出现菜单及菜单定制

    最近实现个功能,展示一段文本,支持用户长按选择复制文本。使用TextView来实现,只需要设置下面属性即可支持: ...

  • 深入了解复制-半同步复制

    1)mysql支持的几种复制形式: 异步复制(Asynchronous replication) MySQL默认的...

  • MYSQL--进阶

    MYSQL主从复制 类别 基于日志点的复制支持MMM和MHA架构 基于GTID方式的复制GTID= source_...

  • 版本方案

    方案一: 标准版-不支持全店复制 全功能版-支持全店复制 标准版:复制个数无限制,功能区别:只能使用商品管理、链接...

  • Hexo--第二弹

    目录 1. Hexo支持流程图、时序图 2. Hexo多行代码提供复制 3. Hexo复制时追加版权 Hexo支持...

  • 第一篇文章

    无法复制? 无法复制文章到这里么?##换行是否支持?## 还是不大习惯如何操作

  • 超好用的命令行工具—cmder

    经常使用cmd,window下的cmd奇丑无比,而且还不支持复制粘贴等功能。 再来看看cmder,他支持复制粘贴,...

网友评论

      本文标题:支持选择复制的richlabel.

      本文链接:https://www.haomeiwen.com/subject/igceextx.html