YYText 与 NSMutableAttributedString

1、字符串部分高亮➕点击事件

- (YYLabel*)createFooterLabelWithHeadString:(NSString*)headStringcontainString:(NSString*)containStringactionBlock:(void(^)())block {

    YYLabel*footerLabel = [[YYLabelalloc]init];

    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:headString];

    footerLabel.font=Font(12);

    attri.yy_color = LightGrayColor;

    if([containStringisValidString]) {

        [attriyy_setTextHighlightRange:[headStringrangeOfString:containString]color:HighlightColorbackgroundColor:ColorCleartapAction:^(UIView*_NonnullcontainerView,NSAttributedString*_Nonnulltext,NSRangerange,CGRectrect) {

            if(block) {

                block();

            }

        }];

    }

    footerLabel.attributedText= attri;

    footerLabel.numberOfLines=0;

    // 设置最大宽度

    footerLabel.preferredMaxLayoutWidth=MainScreenWidth-18;

    footerLabel.textAlignment=NSTextAlignmentLeft;

    returnfooterLabel;

}

2、字符串部分高亮

        NSMutableAttributedString *attributeStr1 = [[NSMutableAttributedString alloc] initWithString:subMessage];

        attributeStr1.yy_font=Font(16);

        attributeStr1.yy_color=RGBHex(@"2A2A2A");

        [attributeStr1yy_setColor:RGBHex(@"F85E56")range:[subMessagerangeOfString:@""]];

       subMessageLabel.attributedText= attributeStr1;

你可能感兴趣的:(YYText 与 NSMutableAttributedString)