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;  //设置富文本
     
    
  • 相关阅读:
    3294 [SCOI2016]背单词
    P4551 最长异或路径
    BZOJ 4260: Codechef REBXOR
    P2322 [HNOI2006]最短母串问题
    P2444 [POI2000]病毒
    P3121 [USACO15FEB]审查(黄金)Censoring (Gold)
    BZOJ 3942: [Usaco2015 Feb]Censoring
    EZOJ #77
    EZOJ #73
    547D Mike and Fish
  • 原文地址:https://www.cnblogs.com/qqcc1388/p/6709336.html
Copyright © 2011-2022 走看看