zoukankan      html  css  js  c++  java
  • YYLabel 自动布局 富文本文字点击事件

    YYLabel显示多行除了需要设置numberOfLines = 0以外,还需要设置preferredMaxLayoutWidth最大的宽度值才可以生效多行效果
    YYLabel中的NSMutableAttributedString可以设置多属性

    yy_lineSpacing 文字行间距
    yy_font 文字的字体大小
    yy_color 文字的颜色
    ...
    通过设置yy_setTextHighlightRange方法可以实现富文本中的文字的点击效果,文字颜色,文字背景颜色等

    eg:

        NSMutableAttributedString *text  = [[NSMutableAttributedString alloc] initWithString: @"接下来,请您咨询阅读《xxx协议》!点击以下同意按钮,即表示您已阅读且完全知悉《xxx协议》约定事项并表示同意!同意后您将正式拥有xxxxxx身份。"];
        text.yy_lineSpacing = 5;
        text.yy_font = [UIFont systemFontOfSize:14];
        text.yy_color = kSystemGrayColor;
        __weak typeof(self) weakself = self;
        [text yy_setTextHighlightRange:NSMakeRange(10, 7) color:[UIColor colorWithHexString:@"0x22b4e1"] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            NSLog(@"xxx协议被点击了");
            if (weakself.agProtocolAction) {
                weakself.agProtocolAction();
            }
        }];
        _agressLabel.numberOfLines = 0;  //设置多行显示
        _agressLabel.preferredMaxLayoutWidth = kScreenWidth - 30; //设置最大的宽度
        _agressLabel.attributedText = text;  //设置富文本
     
    
  • 相关阅读:
    每天一个linux命令
    Python 面向对象-下篇
    Python 面向对象-上篇
    何时会发生隐式类型转换
    C++类型检查
    无符号保留原则
    bool类型为什么可以当做int
    在类的外部定义成员函数注意形式
    局部类
    命名规范
  • 原文地址:https://www.cnblogs.com/qqcc1388/p/6709336.html
Copyright © 2011-2022 走看看