美文网首页
yytext 简单使用

yytext 简单使用

作者: 超_iOS | 来源:发表于2018-06-12 09:12 被阅读32次

    计算高度

     YYTextLayout *layout2 = [YYTextLayout layoutWithContainerSize:CGSizeMake(HOME_SCREEN_WIDTH - 15 * 2, CGFLOAT_MAX) text:rStr];
        h = layout2.textBoundingSize.height;
    

    文字中插入gif图片:

               NSData *data = [NSData dataWithContentsOfFile:path];
               YYImage *image = [YYImage imageWithData:data scale:2];
               image.preloadAllAnimatedImageFrames = YES;
               YYAnimatedImageView *imageView = [[YYAnimatedImageView alloc] initWithImage:image];
               NSMutableAttributedString *attachText = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeCenter attachmentSize:imageView.size alignToFont:font alignment:YYTextVerticalAlignmentCenter];
    [text appendAttributedString:attachText];
    

    插入UIview

    NSString *title = @"This is UIView attachment: ";
            [text appendAttributedString:[[NSAttributedString alloc] initWithString:title attributes:nil]];
            
            UISwitch *switcher = [UISwitch new];
            [switcher sizeToFit];
            
            NSMutableAttributedString *attachText = [NSMutableAttributedString yy_attachmentStringWithContent:switcher contentMode:UIViewContentModeCenter attachmentSize:switcher.size alignToFont:font alignment:YYTextVerticalAlignmentCenter];
            [text appendAttributedString:attachText];
    

    文字添加点击事件高亮:

     [resultStr yy_setTextHighlightRange:range color:RGB(244,190,44) backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
                        DLog(@"点击");
                    }];
    

    相关文章

      网友评论

          本文标题:yytext 简单使用

          本文链接:https://www.haomeiwen.com/subject/cefleftx.html