美文网首页
关于UIButton使用NSLineBreakByTruncat

关于UIButton使用NSLineBreakByTruncat

作者: 灬小五灬 | 来源:发表于2021-08-14 16:00 被阅读0次
前言:这两天使用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)];

相关文章

网友评论

      本文标题:关于UIButton使用NSLineBreakByTruncat

      本文链接:https://www.haomeiwen.com/subject/tmkebltx.html