美文网首页
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 简单使用

    计算高度 文字中插入gif图片: 插入UIview 文字添加点击事件高亮:

  • YYText的简单使用

    在iOS开发中,经常遇到富文本内容的展示,虽然系统的NSAttributedString功能已经比较完善,但是比较...

  • YYText源码分析

    YYText 简单介绍 YYText 是YYKit中的一个富文本显示,编辑组件,拥有YYLabel,YYText...

  • YYText使用

    NSMutableString + YYText实例YYText+add tag制作文字tag 文字附加attac...

  • YYText使用

    YYText官方文档[https://github.com/ibireme/YYText](官方文档写的也很清楚,...

  • YYText使用篇(十一)

    版本记录 前言 YYText是一个专门处理文字的框架,有了它处理文字变得非常方便,这一篇我继续介绍YYText的使...

  • YYText使用篇(七)

    版本记录 前言 YYText是一个专门处理文字的框架,有了它处理文字变得非常方便,这一篇我继续介绍YYText的使...

  • YYText使用篇(五)

    版本记录 前言 YYText是一个专门处理文字的框架,有了它处理文字变得非常方便,这一篇我继续介绍YYText的使...

  • YYText使用篇(四)

    版本记录 前言 YYText是一个专门处理文字的框架,有了它处理文字变得非常方便,这一篇我继续介绍YYText的使...

  • YYText使用篇(一)

    版本记录 前言 YYText是一个专门处理文字的框架,作者是国内的一个技术大牛,他有很多框架,还有我们知道的YYM...

网友评论

      本文标题:yytext 简单使用

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