ibireme / YYText

Powerful text framework for iOS to display and edit rich text.
MIT License
8.84k stars 1.67k forks source link

在iPhone6s 12.3.1 系统 使用YYTextLayout 返回size异常为0 #958

Closed YaoWeiCheng closed 3 years ago

YaoWeiCheng commented 3 years ago

绘制带有格式“你好hello世界”这种样式返回的textBoundingSize所有值为0

YaoWeiCheng commented 3 years ago
NSString *qsText = @"你好hello世界";
UIView *qsTextView = [UIView new];
NSMutableAttributedString *qsTextAttr = [[NSMutableAttributedString alloc] initWithString:qsText];
qsTextAttr.yy_font = [UIFont systemFontOfSize:16];
qsTextAttr.yy_color = [UIColor redColor];
CGFloat qsTextWidth = self.view.frame.size.width - 150;
CGSize qsTextSize = [qsTextAttr boundingRectWithSize:CGSizeMake(qsTextWidth, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size;
YYTextContainer *qsTextContainer = [YYTextContainer containerWithSize:qsTextSize];
YYTextLayout *qsTextLayout = [YYTextLayout layoutWithContainer:qsTextContainer text:qsTextAttr];
YYLabel *label = [YYLabel new];
[self.view addSubview:label];
label.textLayout = qsTextLayout;
label.frame = CGRectMake(100, 100, qsTextLayout.textBoundingSize.width, qsTextLayout.textBoundingSize.height);
label.backgroundColor = [UIColor blueColor];

以上代码在iPhone6s的12.2和12.3系统都能复现