关于UIButton使用NSLineBreakByTruncatingTail

前言:这两天使用UIButton最多展示两行,展示不全是使其...显示到后面位置(UIButton默认显示在中间位置)时,使用以下代码时,在iOS 14系统显示好问题,而在iOS 13系统(目前测试了iOS 13系统)造成文本不换行显示。
_button = [UIButton buttonWithType:UIButtonTypeCustom];
_button.frame = CGRectMake(0, 100, 86, 40);
///设置文本左右内边距
_button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
_button.titleLabel.font = [UIFont systemFontOfSize:12];
///设置文本最多显示两行
_button.titleLabel.numberOfLines = 2;
///设置...显示在后面
_button.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
_button.backgroundColor = [UIColor blackColor];
[_button setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];

在网上找了一些资料也没有找到原因,于是自己修改了lineBreakModenumberOfLines实现的位置。这个问题就没有了,目前考虑到系统兼容性问题,有哪位大神知道原因请告知。
修改之后代码
_button = [UIButton buttonWithType:UIButtonTypeCustom];
_button.frame = CGRectMake(0, 100, 86, 40);
///设置文本左右内边距
_button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
_button.titleLabel.font = [UIFont systemFontOfSize:12];
///设置...显示在后面
_button.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
///设置文本最多显示两行
_button.titleLabel.numberOfLines = 2;
_button.backgroundColor = [UIColor blackColor];
[_button setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容