ibireme / YYText

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

YYTextLayout问题 #87

Closed devSC closed 8 years ago

devSC commented 8 years ago

有如下Code: ` NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:@"It's so huge that I split it into several independent components: YYModel — High performance model framework for iOS. YYCache — High performance cache framework for iOS.YYImage — Image framework for iOS to display/encode/decode animated WebP, APNG, GIF. YYWebImage — Asynchronous image loading framework.YYText — Powerful rich text component for iOS.YYKeyboardManager — Access keyboard view and track keyboard animation."]; attributedText.color = [UIColor whiteColor]; attributedText.font = [UIFont boldSystemFontOfSize:21]; attributedText.lineBreakMode = NSLineBreakByTruncatingTail;

YYTextContainer *textContanier = [YYTextContainer containerWithSize:CGSizeMake(200, 100)];
textContanier.maximumNumberOfRows = 2;
YYTextLayout *layout = [YYTextLayout layoutWithContainer:textContanier text:attributedText];

NSLog(@"textBoundingSize: %@, \n\ntextBoundingRect:  %@", NSStringFromCGSize(layout.textBoundingSize), NSStringFromCGRect(layout.textBoundingRect));`

打印结果是:

` 2015-12-17 18:01:27.655 Being[7679:1849388] textBoundingSize: {185, 26},

textBoundingRect: {{0, 0.0048828125}, {184.5087890625, 25.060546875}} ` 不知道那里出问题了.

ibireme commented 8 years ago

什么问题?

devSC commented 8 years ago

高度计算错误.

ibireme commented 8 years ago

怎么错了? 宽度不对还是高度不对?和实际显示相比呢?

devSC commented 8 years ago

高度不正确. 这边我设置的size为:CGSizeMake(200, 100),现在text这么长, 肯定不止1行,但计算下来,只能显示一行.

ibireme commented 8 years ago

maximumNumberOfRows 限制为最多显示 2 行。 然后这个计算结果是头 2 行的文字宽高。

devSC commented 8 years ago

这里我font设置的是bold_21.如果是2行, 那最少应该也是42吧?

ibireme commented 8 years ago

哦。。 lineBreakMode = NSLineBreakByTruncatingTail; 这一行导致的。 这会阻止文字换行。。

devSC commented 8 years ago

看到了, 感谢.