美文网首页
YYKit是个好东西-YYLabel实现一个文本多个点击事件

YYKit是个好东西-YYLabel实现一个文本多个点击事件

作者: 庄老头 | 来源:发表于2018-04-26 10:19 被阅读1560次

有时候需要实现一个文本多个点击事件的东西,如此图中的用户协议和隐私政策都需要点击跳转对应的页面,可以使用YYLabel来快速实现

NSString *agreementText = @"点击登录即表示已同意并同意《xxx用户协议》与《xxx隐私政策》";

NSMutableAttributedString *text  = [[NSMutableAttributedString alloc] initWithString:agreementText];

text.lineSpacing = 5;//行间距

text.font = [UIFont systemFontOfSize:14];

text.color = [UIColor grayColor];

[text setTextHighlightRange:NSMakeRange(13, 9) color:[UIColor redColor] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {

            NSLog(@"用户协议被点击了");

  }];

        [text setTextHighlightRange:NSMakeRange(agreementText.length-9, 9) color:[UIColor redColor]  backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {

           NSLog(@"隐私政策被点击了");

        }];

YYLabel *agreementLabel = [YYLabel new];

agreementLabel.numberOfLines = 0;//多行

agreementLabel.preferredMaxLayoutWidth = kScreenWidth-85;//最大宽度

agreementLabel.attributedText = text;

[self.view addSubview:agreementLabel];

相关文章

  • YYKit是个好东西-YYLabel实现一个文本多个点击事件

    有时候需要实现一个文本多个点击事件的东西,如此图中的用户协议和隐私政策都需要点击跳转对应的页面,可以使用YYLab...

  • YYKit之YYLabel多个点击事件

    最近,因为这个Lable多个字段点击事件头疼不已,一开始用的别的第三方,最终总是Cell高度计算不准确,纠结了好久...

  • YYText源码分析

    YYText 简单介绍 YYText 是YYKit中的一个富文本显示,编辑组件,拥有YYLabel,YYText...

  • YYKit框架学习之YYLabel

    一、YYLabel 强大的富文本显示功能,可根据文字的range随意添加点击事件 1 自动换行 YYLabel *...

  • YYKit之YYLabel

    本文只对富文本中部分文字添加点击事件做简单介绍 1.添加点击事件 YYLabel中给部分文字添加点击事件主要是在富...

  • JQuery-事件触发

    事件触发 有个文本框有这么一个事件 现在要实现点击按钮,触发这个事件,有下面三种方式 // 现在要实现点击按钮,触...

  • iOS实现图文混排及点击事件和高亮背景。

    通过CoreText和富文本,能够实现图文混排和点击事件。在实现点击事件时,能够对指定文本实现背景高亮。demo地...

  • YYLabel简单使用

    最近尝试研究了一下YYLabel,学习了一下YYLabel文本响应点击及YYLabel换行功能,下面介绍一下我的收...

  • YYLabel的简单使用

    不得不说 YYKit 框架确实很牛,其YYLabel组件在富文本显示和操作方面相当强大,尤其是其异步渲染,让界面要...

  • YYText 与 NSMutableAttributedStri

    1、字符串部分高亮➕点击事件 - (YYLabel*)createFooterLabelWithHeadStrin...

网友评论

      本文标题:YYKit是个好东西-YYLabel实现一个文本多个点击事件

      本文链接:https://www.haomeiwen.com/subject/uylplftx.html