zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    MongoDB学习笔记~大叔分享批量添加—批量更新—批量删除
    Eclipse常用快捷键
    UDP 通信
    HDU 3571 N-dimensional Sphere(高斯消元 数论题)
    【机器学习】SVM核函数
    获取CentOS软件源中的updates包
    13年7月13日CF练习 Codeforces Round #147 (Div. 2)
    VMware vSphere 服务器虚拟化之二十八 桌面虚拟化之安装View传输服务器
    .net下灰度模式图像在创建Graphics时出现:无法从带有索引像素格式的图像创建graphics对象 问题的解决方案。
    庖丁图解八皇后问题
  • 原文地址:https://www.cnblogs.com/qiutangfengmian/p/4962282.html
Copyright © 2011-2022 走看看