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

  • 相关阅读:
    49. Group Anagrams
    43. Multiply Strings
    22. Generate Parentheses
    17. Letter Combinations of a Phone Number
    8. String to Integer (atoi)
    【转】C#中base关键字的几种用法:base()
    【转】C#中virtual和abstract的区别
    [转]C#中的abstract 类和方法
    【转】C#虚方法virtual详解
    【转】C#中protected用法详解
  • 原文地址:https://www.cnblogs.com/qiutangfengmian/p/4962282.html
Copyright © 2011-2022 走看看