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;

你可能感兴趣的:(yylabel添加高亮点击字体)