yytext 简单使用

2018-06-12  本文已影响32人  超_iOS

计算高度

 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(@"点击");
                }];
上一篇 下一篇

猜你喜欢

热点阅读