• TTTAttributedLabel使用介绍(转)


     TTTAttributedLabel 库地址 https://github.com/TTTAttributedLabel/TTTAttributedLabel

    可以实现电话  地址  链接自动查找显示等

        //可以自动检测url

        label.enabledTextCheckingTypes = NSTextCheckingTypeLink;

        

        label.delegate = self; // Delegate

        //NO 不显示下划线

    //    label.linkAttributes = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:(NSString *)kCTUnderlineStyleAttributeName];

        

        [label setText:bm.Content afterInheritingLabelAttributesAndConfiguringWithBlock:^ NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString)

         {

    //         //设定可点击文字的的大小

    //         UIFont *boldSystemFont = [UIFont boldSystemFontOfSize:16];

    //         CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)boldSystemFont.fontName, boldSystemFont.pointSize, NULL);

    //         

    //         if (result) {

    //             

    //             //设置可点击文本的大小

    //             [mutableAttributedString addAttribute:(NSString *)kCTFontAttributeName value:(__bridge id)font range:result.range];

    //             

    //             //设置可点击文本的颜色

    //             [mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[[UIColor blueColor] CGColor] range:result.range];

    //             CFRelease(font);

    //

    //         }

             return mutableAttributedString;

         }];

       NSString *urlString = [[bm.Content substringWithRange:result.range] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];

        NSURL *url = [[NSURL alloc]initWithString:urlString];

        

        //设置链接的url

        [label addLinkToURL:url withRange:result.range];

     }

    //链接点击事件

    - (void)attributedLabel:(__unused TTTAttributedLabel *)label

       didSelectLinkWithURL:(NSURL *)url

    {

        NSString *str = [url absoluteString];

        NSString *decodeStr = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        if ([[decodeStr substringToIndex:1] isEqualToString:@"#"]) {

        }

        else

        {

        //为链接 打开链接

        [[[UIActionSheet alloc] initWithTitle:[url absoluteString] delegate:self cancelButtonTitle:NSLocalizedString(@"取消", nil) destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"在浏览器中打开连接", nil), nil] showInView:self.view];

        }

    }

    http://blog.csdn.net/lengshengren/article/details/43971441

  • 相关阅读:
    vs2015驱动开发中使用RtlStringCchPrintfW()报错
    windbg双机调试配置
    修改Windows默认调试器
    kong配置service和route实现简单API代理
    konga的初步使用
    Kong Admin API — 核心对象
    Kong的API管理方式
    kong的管理UI选择-konga
    Kong 安装
    关于kong | API Gateway
  • 原文地址:https://www.cnblogs.com/qiutangfengmian/p/4962282.html
Copyright © 2020-2023  润新知