TYAttributedLabel的使用
程序员文章站
2022-06-21 20:02:33
//提示内容 lblContent=[[TYAttributedLabel alloc]init]; [bgView addSubview:lblContent]; lblContent.delegate=self; NSString *text = @" 温馨提示\n亲,感谢您对xxxx一直以来的信任!更新了xxxx《aaaa》和《bbbb》,特向您说明如下:\n1、为您xxxxxxxxxxxxx"; [lblContent setText:text....
#import "TYAttributedLabel.h"
//提示内容
lblContent=[[TYAttributedLabel alloc]init];
[bgView addSubview:lblContent];
lblContent.delegate=self;
NSString *text = @" 温馨提示\n亲,感谢您对xxxx一直以来的信任!更新了xxxx《aaaa》和《bbbb》,特向您说明如下:\n1、为您xxxxxxxxxxxxx";
[lblContent setText:text];
// 文字间隙
lblContent.characterSpacing = 2;
// 文本行间隙
lblContent.linesSpacing = 5;
TYTextStorage * titleStorage = [[TYTextStorage alloc]init];
titleStorage.range = [text rangeOfString:@"温馨提示"];
titleStorage.textColor =[UIColor hx_colorWithHexString:blackFontColor];
titleStorage.font = [UIFont boldSystemFontOfSize:20];
[lblContent addTextStorage:titleStorage];
TYTextStorage * textStorage = [[TYTextStorage alloc]init];
textStorage.range = [text rangeOfString:@"《aaaa》"];
textStorage.textColor =[UIColor hx_colorWithHexString:navBarColor];
textStorage.font = [UIFont boldSystemFontOfSize:14];
[lblContent addTextStorage:textStorage];
TYTextStorage * privacyStorage = [[TYTextStorage alloc]init];
privacyStorage.range = [text rangeOfString:@"《bbbb》"];
privacyStorage.textColor =[UIColor hx_colorWithHexString:navBarColor];
privacyStorage.font = [UIFont boldSystemFontOfSize:14];
[lblContent addTextStorage:privacyStorage];
//添加超链接
[lblContent addLinkWithLinkData:@"aaaa" linkColor:[UIColor hx_colorWithHexString:navBarColor] underLineStyle:kCTUnderlineStyleNone range:[text rangeOfString:@"《aaaa》"]];
//添加超链接
[lblContent addLinkWithLinkData:@"bbbb" linkColor:[UIColor hx_colorWithHexString:navBarColor] underLineStyle:kCTUnderlineStyleNone range:[text rangeOfString:@"《bbbb》"]];
[lblContent sizeToFit];
CGFloat height_lblContent=[lblContent getSizeWithWidth:gScreenWidth-20].height;
[lblContent mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(20);
make.left.mas_equalTo(10);
make.right.mas_equalTo(-10);
make.height.mas_equalTo(height_lblContent);
make.bottom.mas_equalTo(-80);
}];
添加协议
<TYAttributedLabelDelegate>
点击超链接
#pragma mark - Delegate
//TYAttributedLabelDelegate
- (void)attributedLabel:(TYAttributedLabel *)attributedLabel textStorageClicked:(id<TYTextStorageProtocol>)TextRun atPoint:(CGPoint)point {
if ([TextRun isKindOfClass:[TYLinkTextStorage class]]) {
NSString *linkStr = ((TYLinkTextStorage*)TextRun).linkData;
if ([linkStr isEqualToString:@"aaaa"]) {
WYWebController *webVC = [WYWebController new];
webVC.mTitle = @"aaaa";
webVC.url =@"aaa";
webVC.hidesBottomBarWhenPushed=YES;
[self.nav pushViewController:webVC animated:YES];
}else{
WYWebController *webVC = [WYWebController new];
webVC.mTitle = @"bbbb";
webVC.url =@"bbbb"
webVC.hidesBottomBarWhenPushed=YES;
[self.nav pushViewController:webVC animated:YES];
}
}
}
本文地址:https://blog.csdn.net/weixin_43205520/article/details/107366075
上一篇: 架构之AOP面向切面架构设计
推荐阅读
-
二本压线的公办大学理科?接近二本线的公办大学名单(2021年参考)
-
民办专科有必要读吗学费太贵?全国比较好的民办大专有哪些?
-
javascript下搜索子字符串的的实现代码(脚本之家修正版)_javascript技巧
-
jquery 使用点滴函数代码_jquery
-
日常收集整理的JavaScript常用函数方法_javascript技巧
-
输入值/表单提交参数过滤有效防止sql注入的方法_PHP
-
抓取微博热词,使用simple_html_dom来操作html数据
-
固定右栏宽度, 左栏内容先出现同时自适应宽度的布局
-
老生常谈反射之Class类的使用(必看篇)
-
微博开发1客户端的http的get和post封装