ibireme / YYText

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

NSLineBreakByTruncatingMiddle 模式下只展示一行? #899

Open ShouBinCheng opened 5 years ago

ShouBinCheng commented 5 years ago
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:self.model.describe];
text.yy_font = [TXSakura getFontWithPath:@"m.16"] ?: [UIFont systemFontOfSize:16];
text.yy_color = [TXSakura getColorWithPath:HomeTheme.textColorMain];
text.yy_lineBreakMode = NSLineBreakByTruncatingMiddle;

YYTextContainer *container = [YYTextContainer containerWithSize:CGSizeMake(LBConst.screenWidth-40, INT_MAX)];
container.maximumNumberOfRows = 4;
YYTextLayout *textLayout = [YYTextLayout layoutWithContainer:container text:text];

设置text.yy_lineBreakMode = NSLineBreakByTruncatingMiddle; 后label只展示一行,怎么让它展示设定的最大行数

lilongcnc commented 4 years ago

不要用这种方式设置。 直接用label或者container, 不过middle模式有点问题,目前我也还在找答案

lilongcnc commented 4 years ago

找到了一个方案 https://www.jianshu.com/p/f87b07668740