Coder Social home page Coder Social logo

yhct's Introduction

YHCT

利用CoreText实现的图文混排组件,适合聊天界面、Timeline等。可自动解析手机号码、超链接,也可以自定义点击事件。长按会弹出复制、举报(自定义菜单项)。

image

使用方法:

1、初始化

self.yhTextView = [[YHCoreTextView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 300)];

self.yhTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleRightMargin;

[self addSubview:self.yhTextView];

2、赋值

NSString text = @"自定义事件<a href='hehe://1023'>click me</a>。手机号码1862345543233444超链接https://www.apple.com自动[ok]解析[hello]表[下雨]图片,如果中括号中的图片找不多,会原封不动的显示字符串[duang].";

YHCTData *nameData = [YHCTData instanceYHCTDataWith:text originText:text];

[nameData useDefaultSetting];//使用默认设置

self.yhTextView.yhctData = nameData;

3、事件捕捉

 void(^linkClickAction)(YHCTLinkData* linkData) = ^(YHCTLinkData* linkData){
     
    NSString *action = linkData.action;
    
    if ([action isEqualToString:@"http"] || [action isEqualToString:@"https"]){
    
        NSString *url = [NSString stringWithFormat:@"%@://%@",action,linkData.query];
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"打开网页" message:url delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        
        [alert show];
        
    }else if ([action isEqualToString:@"tel"]){
    
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"拨打电话" message:linkData.query delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];

        [alert show];
        
    }else {
    
        NSString *msg = [NSString stringWithFormat:@"action:%@ params:%@",linkData.action,linkData.query];
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"自定义" message:msg delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        
        [alert show];
        
    }
    
};

self.yhTextView.linkClickAction = linkClickAction;

self.yhTextView.otherMenus = @[@"收藏",@"举报"];

self.yhTextView.otherMenuClickAction = ^(NSString *title){

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:title delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
    
    [alert show];
    
};

yhct's People

Contributors

yehongzhou avatar

Stargazers

HaiYang Chen avatar  avatar Bob Edmonston avatar phelps avatar Figo.Xu avatar

Watchers

James Cloos avatar  avatar

Forkers

figoxu

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.