關(guān)于UIButton使用NSLineBreakByTruncatingTail

前言:這兩天使用UIButton最多展示兩行,展示不全是使其...顯示到后面位置(UIButton默認(rèn)顯示在中間位置)時(shí),使用以下代碼時(shí),在iOS 14系統(tǒng)顯示好問(wèn)題,而在iOS 13系統(tǒng)(目前測(cè)試了iOS 13系統(tǒng))造成文本不換行顯示。
_button = [UIButton buttonWithType:UIButtonTypeCustom];
_button.frame = CGRectMake(0, 100, 86, 40);
///設(shè)置文本左右內(nèi)邊距
_button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
_button.titleLabel.font = [UIFont systemFontOfSize:12];
///設(shè)置文本最多顯示兩行
_button.titleLabel.numberOfLines = 2;
///設(shè)置...顯示在后面
_button.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
_button.backgroundColor = [UIColor blackColor];
[_button setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];

在網(wǎng)上找了一些資料也沒有找到原因,于是自己修改了lineBreakModenumberOfLines實(shí)現(xiàn)的位置。這個(gè)問(wèn)題就沒有了,目前考慮到系統(tǒng)兼容性問(wèn)題,有哪位大神知道原因請(qǐng)告知。
修改之后代碼
_button = [UIButton buttonWithType:UIButtonTypeCustom];
_button.frame = CGRectMake(0, 100, 86, 40);
///設(shè)置文本左右內(nèi)邊距
_button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
_button.titleLabel.font = [UIFont systemFontOfSize:12];
///設(shè)置...顯示在后面
_button.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
///設(shè)置文本最多顯示兩行
_button.titleLabel.numberOfLines = 2;
_button.backgroundColor = [UIColor blackColor];
[_button setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容