• iOS 开发富文本之TTTAttributedLabel 在某个特定位置的文字添加跳转,下划线,修改字体大小,颜色


    1 @property(nonatomic , strong) TTTAttributedLabel * ttLabel;
    2 @property(nonatomic , strong) NSRange lineboldRange;
    3 @property(nonatomic , strong) NSRange lineboldRange1;
    全局变量
     1 _ttLabel = [[TTTAttributedLabelalloc]initWithFrame:CGRectMake(10,80,self.view.width-20,50)];
     2 _ttLabel.numberOfLines = 0;
     3 _ttLabel.lineSpacing = 10;
     4 _ttLabel.font = [UIFontsystemFontOfSize:13];
     5 _ttLabel.textColor = [UIColorlightGrayColor];
     6 _ttLabel.delegate = self;
     7 //检测url
     8 _ttLabel.enabledTextCheckingTypes=NSTextCheckingTypeLink;
     9 //对齐方式
    10 _ttLabel.verticalAlignment=TTTAttributedLabelVerticalAlignmentTop;
    11 [self.viewaddSubview:_ttLabel];
    12 NSString*tempStr =@"确定讲银行卡更换为尾号为6723的建设银行的银行卡
    同意《自动扣款协议》和《快捷支付服务协议》";
    13 CGSizetSize = [_ttLabelsetLines:5 andText:tempStrMWidth:(self.view.width-20)LineSpacing:10];
    14 _ttLabel.frame=CGRectMake(10,80,self.view.width-20, tSize.height+20);
    15 [_ttLabelsetText:tempStrafterInheritingLabelAttributesAndConfiguringWithBlock:^NSMutableAttributedString*(NSMutableAttributedString*mutableAttributedString)
    16   {
    17     //设置可点击文字的范围
    18     NSRangeboldRange = [[mutableAttributedStringstring]rangeOfString:@"《自动扣款协议》"options:NSCaseInsensitiveSearch];
    19     _lineboldRange = boldRange;
    20     NSRangeboldRange1 = [[mutableAttributedStringstring]rangeOfString:@"《快捷支付服务协议》"options:NSCaseInsensitiveSearch];
    21     _lineboldRange1 = boldRange1;
    22     //设定可点击文字的的大小
    23     UIFont*boldSystemFont = [UIFontsystemFontOfSize:15];
    24     CTFontReffont =CTFontCreateWithName((__bridgeCFStringRef)boldSystemFont.fontName, boldSystemFont.pointSize,NULL);
    25     if(font)
    26     {
    27       //设置可点击文本的大小
    28       [mutableAttributedStringaddAttribute:(NSString*)kCTFontAttributeNamevalue:(__bridgeid)fontrange:boldRange];
    29       [mutableAttributedStringaddAttribute:(NSString*)kCTFontAttributeNamevalue:(__bridgeid)fontrange:boldRange1];
    30       //设置可点击文本的颜色
    31       [mutableAttributedStringaddAttribute:(NSString*)kCTForegroundColorAttributeNamevalue:(id)[[UIColorblackColor]CGColor]range:boldRange];
    32       [mutableAttributedStringaddAttribute:(NSString*)kCTForegroundColorAttributeNamevalue:(id)[[UIColorblackColor]CGColor]range:boldRange1];
    33       //添加下划线
    34       [mutableAttributedStringaddAttribute:NSUnderlineStyleAttributeNamevalue:[NSNumbernumberWithInteger:NSUnderlineStyleSingle]range:boldRange];
    35       [mutableAttributedStringaddAttribute:NSUnderlineStyleAttributeNamevalue:[NSNumbernumberWithInteger:NSUnderlineStyleSingle]range:boldRange1];
    36       CFRelease(font);
    37     }
    38     returnmutableAttributedString;
    39   }];
    40 NSURL*firstUrl = [NSURLURLWithString:@"http://www.baidu.com"];
    41 NSURL*lastUrl = [NSURLURLWithString:@"http://www.xiaomi.com"];
    42 //添加url
    43 [_ttLabeladdLinkToURL:firstUrlwithRange:_lineboldRange];
    44 [_ttLabeladdLinkToURL:lastUrlwithRange:_lineboldRange1];
    1 #pragma mark ------  TTTAttributedLabelDelegate ------
    2 - (void)attributedLabel:(TTTAttributedLabel*)label didSelectLinkWithURL:(NSURL*)ur
    3 {
    4   NSLog(@"打印设置的URL%@进行跳转处理",url);
    5 }
  • 相关阅读:
    SharePoint安全性验证无效
    纠结的TreeView动态加载节点
    Microsoft CRM 安装问题汇总
    moss里用Response生成Excel以后页面按钮失效问题
    zt:System.Globalization 命名空间
    ZT:自定义的泛型类和泛型约束
    开博了,,,
    zt:SilverLight遍历父子控件的通用方法
    zt: 学习WPF绑定
    zt:使用复杂类型定义模型(实体框架)
  • 原文地址:https://www.cnblogs.com/ChenHuChang/p/5720669.html
Copyright © 2020-2023  润新知