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

效果图:



/*

    注意事项:

            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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值