用YYText做富文本编辑开发实在是坑点太多.
-
YYTextView中没有做异步渲染,导致超长文本输入特别卡,而且如果有图文的长篇内容无法渲染.
-
yytext中内容本地化,(将富文本转为data)必须在主线程中处理.比如里面的图片<UIImageView>和增加的其他富文本View初始化就必须在主线程中处.
YYLabel 异步渲染
_label = [YYLabel new];
_label.displaysAsynchronously = YES; //开启异步绘制
_label.ignoreCommonProperties = YES;
_label.numberOfLines = 2;
_label.font = FontRegular(14);
_label.lineBreakMode = NSLineBreakByTruncatingTail;
_label.userInteractionEnabled = YES;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// 创建文本容器
YYTextContainer *container = [YYTextContainer new];
container.size = CGSizeMake(ScreenWidth - 90, CGFLOAT_MAX);
container.maximumNumberOfRows = 2;
// 生成排版结果
YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:likeItemModel.likesStr];
YYTextBorder *border = [[YYTextBorder alloc]init];
border.insets = UIEdgeInsetsMake(-2, 0, -2, 0);
border.cornerRadius = 3;
border.fillColor = [UIColor clearColor];
dispatch_async(dispatch_get_main_queue(), ^{
_label.size = layout.textBoundingSize;
_label.textLayout = layout;
});
});
网友评论