gpt4 book ai didi

ios - 当 UIButton 达到最大行数时收缩标题标签文本

转载 作者:行者123 更新时间:2023-11-28 22:17:50 25 4
gpt4 key购买 nike

我有一个 UIButton,我想根据 NSString 的大小调整文本字体的大小。我希望最大行数 为 3,如果 NSString 长度超过 3 行,则字体会缩小,直到显示所有文本。这是我目前所拥有的:

button.titleLabel.textAlignment = NSTextAlignmentCenter;
button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;

button.titleLabel.adjustsFontSizeToFitWidth = YES;
button.titleLabel.numberOfLines = 3;

然而这段代码并没有如我所愿;如果 NSString 超过 3 行,则 UIButton 文本包含 ...。有什么想法吗?

最佳答案

当您想要缩小文本时设置lineBreakMode 是一个错误。只需删除设置 lineBreakMode 的行即可。

关于ios - 当 UIButton 达到最大行数时收缩标题标签文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21172496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com