Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于 文字超出label范围的省略号(...)的问题 #344

Closed
CoderLXWang opened this issue May 30, 2016 · 12 comments
Closed

关于 文字超出label范围的省略号(...)的问题 #344

CoderLXWang opened this issue May 30, 2016 · 12 comments

Comments

@CoderLXWang
Copy link

如下代码, 设置了最多显示4行, 最后一行尾部没有省略号, 不知道这个怎么设置会显示出来
` NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:model.content];
attString.yy_font = [UIFont systemFontOfSize:13];
attString.yy_lineSpacing = 10;

CGSize size = CGSizeMake(SCREEN_WIDTH-2*11-2*20, CGFLOAT_MAX);
YYTextContainer *container = [YYTextContainer containerWithSize:size];
container.maximumNumberOfRows = 4;
YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:attString];
CGFloat layoutHeight = layout.textBoundingSize.height;

self.contentLabel.attributedText = attString;
self.contentLabel.textLayout = layout;

[self.bgImgView addSubview:self.contentLabel];
[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(self.starView.mas_bottom).offset(20);
    make.left.equalTo(self.iconImgView);
    make.right.equalTo(self.bgImgView).offset(-20);
    make.height.mas_equalTo(layoutHeight);
}];`
@ibireme
Copy link
Owner

ibireme commented May 30, 2016

试试

container.truncationType = YYTextTruncationTypeEnd;

@CoderLXWang
Copy link
Author

可以了, 十分感谢, 另外问一下, 这套框架可以设置一行内的字间距吗?

@CoderLXWang
Copy link
Author

刚才又试了一下YYTextTruncationTypeStart , 超过四行时显示效果为, 最后一行前后都有省略号, 设置为YYTextTruncationTypeMiddle, 超过四行, 最后一行中间和末尾都有省略号, 这个效果可能有一些问题

@ibireme
Copy link
Owner

ibireme commented May 31, 2016

字间距用 attributedString 的 kern 属性来调节。

truncation 这个属性,多行下 start 和 middle 确实表现不对,是之前在调整 truncation 裁剪方式的时候引入的问题。这个之后会进行修复。

@CoderLXWang
Copy link
Author

好的, 十分感谢

@WuiX
Copy link

WuiX commented Jun 1, 2016

@ibireme 请问,最后的省略号可以自定义吗,我现在的做法是自己计算行数把最后一行的几个字替换成我想自定义的字,就像这种效果:
第一行ZZZZZZZZZZZZZZZZ
第二行ZZZZZZZZZZZZZZZZ
第三行ZZZZZZZZZZZZZZZZ
第四行ZZZZZZZZ#查看全文#

@ibireme
Copy link
Owner

ibireme commented Jun 1, 2016

Demo 中就有例子,可以自定义 trunctionToken。

@CoderLXWang
Copy link
Author

不好意思, Demo中有trunctionToken 的例子吗, 没有看到, 我全局搜trunctionToken也搜不到, 搜trunction到时可以找到trunctionType, 其他的没看到

@ibireme
Copy link
Owner

ibireme commented Jun 1, 2016

拼错了。。truncationToken

@WuiX
Copy link

WuiX commented Jun 2, 2016

谢谢,我试了下可以为YYTextContainer 设置trunctionToken来自定义截断显示,但是点击的事件不是在正常的将YYTextLayout赋值给的YYLabel里,而是在生成truncationToken的YYLbel里面

@ibireme
Copy link
Owner

ibireme commented Jun 2, 2016

是的, Truncation 响应不了点击事件。
那么,还是看 Demo 中的例子吧:https://github.com/ibireme/YYText/blob/master/Demo/YYTextDemo/YYTextAttachmentExample.m#L120-L141

@ibireme ibireme closed this as completed Jun 15, 2016
@Yuan920
Copy link

Yuan920 commented Feb 13, 2019

字间距用 attributedString 的 kern 属性来调节。

truncation 这个属性,多行下 start 和 middle 确实表现不对,是之前在调整 truncation 裁剪方式的时候引入的问题。这个之后会进行修复。

请问这个是否已经修复?感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants