TTTAttributedLabel第三方使用(一段连续的字符串不同范围用不同字体和颜色)
2016-04-21 00:00
218 查看
事例代码
添加链接并调用的协议:
- (void)attributedLabel:(TTTAttributedLabel *)label
didSelectLinkWithURL:(NSURL *)url;
TTTAttributedLabel *detailLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(_mycheckBox.right+8, 13, 200, 20)]; NSString *detail = @"确认《协议书》及《风险揭示书》"; NSMutableAttributedString *detailStr = [[NSMutableAttributedString alloc] initWithString:detail]; [detailStr addAttribute:(NSString *)NSForegroundColorAttributeName value:CS_Color_DeepGray range:NSMakeRange(0, 2)]; [detailStr addAttribute:(NSString *)NSForegroundColorAttributeName value:UIColorFromRGB(0x1A9BFC) range:NSMakeRange(2, 5)]; [detailStr addAttribute:(NSString *)NSForegroundColorAttributeName value:CS_Color_DeepGray range:NSMakeRange(7, 1)]; [detailStr addAttribute:(NSString *)NSForegroundColorAttributeName value:UIColorFromRGB(0x1A9BFC) range:NSMakeRange(8, 7)]; [detailStr addAttribute:(NSString *)kCTFontAttributeName value:[UIFont fontWithName:@"STHeitiSC-Light" size:13.0f] range:NSMakeRange(0, detail.length)]; [detailLabel setAttributedText:detailStr]; [detailLabel setDelegate:self]; detailLabel.numberOfLines = 0; detailLabel.lineBreakMode = NSLineBreakByCharWrapping; detailLabel.linkAttributes = @{ (NSString *)kCTUnderlineStyleAttributeName : @NO, (NSString *) NSForegroundColorAttributeName : CS_Color_StandGreen2 }; NSURL *linkOne = [NSURL URLWithString:@"protocol"];//添加链接 NSURL *linkTow = [NSURL URLWithString:@"risk"]; [detailLabel addLinkToURL:linkOne withRange:NSMakeRange(2, 5)]; [detailLabel addLinkToURL:linkTow withRange:NSMakeRange(8, 7)]; //链接的实现: #pragma mark - #pragma mark TTTAttributedLabel Delegate - (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url { if ([url.absoluteString isEqualToString:@"protocol"]) { [self queryProductProtocol]; } else { [self queryProductRisk]; } }
添加链接并调用的协议:
- (void)attributedLabel:(TTTAttributedLabel *)label
didSelectLinkWithURL:(NSURL *)url;
相关文章推荐
- 麒麟来源堡垒机设计原理
- Hadoop核心
- Hadoop项目组成
- 什么是三级分销
- 今日总结
- 实力代码对比工具,你get√了没?
- 文件对比工具 Beyond Compare
- python浓缩(15)
- python浓缩(16)网络编程
- JAVA二维码生成
- iOS关于系统键盘的长度限制
- 第一次作业(3.数据结构)
- Android FrameWork——Touch事件派发过程详解
- 《将博客搬至CSDN》
- (27)Spring Boot Junit单元测试【从零开始学Spring Boot】
- 个人总结之完全退出程序
- 个人总结之H5调用本地app
- 局域网内访问虚拟机
- 怎样维护 SQLite
- Navicat for SQLite 表检查知识要点