加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式在内容里面标示 @昵称 #话题# url

发布时间:2020-12-14 01:10:35 所属栏目:百科 来源:网络整理
导读:效果图: /* 注意事项: 1. 使用之前需要倒入 libicucore.dylib And CoreText.framework 2. 此类使用了 ARC 管理内存 3. 如果你的项目是非 ARC 项目,你需要在文件添加 -fobjc-arc 的标示(非 ARC 标示 -fno-objc-arc ) */ 使用方法: //7.文本 WXLabel *te

效果图:



/*

注意事项:

1.使用之前需要倒入 libicucore.dylib And CoreText.framework

2.此类使用了ARC管理内存

3.如果你的项目是非ARC项目,你需要在文件添加-fobjc-arc的标示(非ARC标示-fno-objc-arc

*/


使用方法:

        //7.文本
        WXLabel *text = [[WXLabel alloc] init];
        [self.topView addSubview:text];
        text.font = textFont;
        text.numberOfLines = 0;
        [text sizeToFit];
//        text.colorName = @"Theme_Main_color";
        self.text = text;
        self.text.wxLabelDelegate = self;

#pragma mark - WXLabelDelegate

//(1)检索文本的正则表达式的字符串
- (NSString *)contentsOfRegexStringWithWXLabel:(WXLabel *)wxLabel {
    
    //@某人   #话题#   http(s)://......
    
    //@某人
    NSString *people = @"@w+";
    
    //#话题#
    NSString *topic = @"#[^#]+#";
    
    //网址  http(s)://www.baidu.com/www.baidu.com/www.baidu.com/
    //     NSString *regex3 = @"http(s)?://([a-zA-Z0-9._-]+(/)?)*";
    //     NSString *regex3 = @"http(s)?://([a-zA-Z0-9._-/?]+)*";
    
    NSString *httpStr = @"bhttps?://[a-zA-Z0-9-.]+(?::(d+))?(?:(?:/[a-zA-Z0-9-._?,'+&%$=~*!():@\]*)+)?";
    
    NSString *result = [NSString stringWithFormat:@"%@|%@|%@",people,topic,httpStr];
    
    return result;
}

//(2)设置当前超链接的颜色
- (UIColor *)linkColorWithWXLabel:(WXLabel *)wxLabel {
    
    UIColor *color = [[ThemeManager shareInstance] getThemeColor:@"Link_color"];
    
    return color;
}

//(3)设置当前文本手指经过的颜色
- (UIColor *)passColorWithWXLabel:(WXLabel *)wxLabel {
    
    UIColor *color = [UIColor grayColor];
    
    return color;
}

//(4)点击超链接响应的代理方法
//context里面是设置的正则检索字符串,此方法在点击这些字符串时会调用
- (void)toucheEndWXLabel:(WXLabel *)wxLabel withContext:(NSString *)context {

    NSLog(@"context:%@",context);
    
}


类库链接: http://pan.baidu.com/s/1nt47LKt 密码: qrei

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读