Giter Site home page Giter Site logo

fishmemory / grichlabel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gikicoder/grichlabel

0.0 2.0 0.0 9.23 MB

A rich Label that supports selection, copying. 支持文本选择的RichLabel.小说阅读器.Feed流文本

License: MIT License

Objective-C 99.83% Ruby 0.17%

grichlabel's Introduction

GRichLabel

A rich Label that supports selection, copying.

Features

  • 1,基于coretext绘制文本.内部使用YYAsyncLayer提供异步绘制任务
  • 2,支持选择/复制文本.
  • 3,支持自定义表情排版
  • 4,可自定义文本选择弹出menuView GMenuContoller
  • 5,对于文本token 采用多模匹配算法. 详见GMatcherExpression.文本匹配效率比系统字符串匹配效率提高百倍.
  • 6,功能以及代码还在更新完善中. 后期会支持更多功能.欢迎star.
  • 7,支持文本在滚动视图中做文本滚动选择 (微信聊天气泡文本选择)

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

Installation

  • 手动添加
  1. git clone https://github.com/GIKICoder/GRichLabel.git
  2. 选择GRichLabel文件夹.拖入项目中.
  3. GRichLabel 依赖 GMenuController https://github.com/GIKICoder/GMenuController,  YYAsyncLayer https://github.com/ibireme/YYAsyncLayer 这2个库. 可以使用pod添加. 也可下载手动添加到项目

update Info

  • 29/10/2017 代码重构.处理耦合逻辑.简化代码.重新整理NSAttributedString分类(参考NSAttributedString+YYText).使GRichLabel具有更强大的文本处理能力.
  • 06/12/2017 增加kGAttributeTokenReplaceStringName. 支持自定义表情 链接等字符串copy 处理.
  • 19/04/2018 增加GMatherExpression 增加字符匹配模式.
  • 27/08/2018 增加文本选择模式,在滚动视图下可支持滚动文本选择。

screenshot

grichlabel's People

Contributors

gikicoder avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.