ios - 动态缩放 UIButton 中的字体
<p><p>刚刚更新了我之前的问题
<a href="https://stackoverflow.com/q/46282641/6135493" rel="noreferrer noopener nofollow">How to scale the fonts in a Button</a>
仍然没有答案
问题描述 - 我从 main.storyboard 界面创建了一些 UIButtons。按钮有一些标题。当我使用约束时,按钮大小会随着我更改设备屏幕大小而增加。同时,标题字体保持不变,所以我有带有非常小的标题的大按钮。当我使用带有小屏幕的设备作为 iPhone4 时,标题会从按钮边缘消失。
我试过了</p>
<pre><code>@IBAction func touchDigit(_ sender: UIButton) {
sender.titleLabel?.minimumScaleFactor = 0.5;
sender.titleLabel?.numberOfLines = 0
sender.titleLabel?.adjustsFontSizeToFitWidth = true
</code></pre>
<p>我使用可检查变量为按钮创建了类</p>
<pre><code>@IBInspectable var adjustFontSize : Bool {
set { titleLabel?.adjustsFontForContentSizeCategory = newValue }
get { return titleLabel!.adjustsFontForContentSizeCategory}
}
</code></pre>
<p> 没有效果。
UILabel 有自动调整字体复选框。 UIButton 没有。
我相信每个人都有这样的问题,解决方案似乎很简单。请帮忙找一下!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>使用这个:</p>
<pre><code>sender.titleLabel?.lineBreakMode = .byClipping
</code></pre></p>
<p style="font-size: 20px;">关于ios - 动态缩放 UIButton 中的字体,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/46495128/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/46495128/
</a>
</p>
页:
[1]