yylabel添加高亮点击字体

    NSMutableAttributedString *muAtt = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@%@",model.username,model.entitytypename,model.entityname]];
    
    [muAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, muAtt.length)];
    
    [muAtt setTextHighlightRange:NSMakeRange(0, model.username.length)
                         color:HEXCOLOR(0x1cb177)
               backgroundColor:self.titleLabel.backgroundColor
                     tapAction:^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect) {
                         NSLog(@"%@",[NSString stringWithFormat:@"Tap: %@", [text.string substringWithRange:range]]);
                     }];
    
    [muAtt setTextHighlightRange:NSMakeRange(muAtt.length - model.entityname.length, model.entityname.length)
                         color:HEXCOLOR(0x1cb177)
               backgroundColor:self.titleLabel.backgroundColor                     tapAction:^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect) {
                         NSLog(@"%@",[NSString stringWithFormat:@"Tap: %@", [text.string substringWithRange:range]]);
                     }];


    
    self.titleLabel.attributedText = muAtt;
//    self.titleLabel.preferredMaxLayoutWidth = SCREEN_WIDTH -32;

    CGSize maxSize = CGSizeMake([UIScreen mainScreen].bounds.size.width - 32, MAXFLOAT);
    
    //计算文本尺寸
    YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:maxSize text:muAtt];
    self.titleLabel.textLayout = layout;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容