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的建设银行的银行卡\n同意《自动扣款协议》和《快捷支付服务协议》";
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 }

 

转载于:https://www.cnblogs.com/missCH/p/5720669.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值