ios - NSAttributedText 字体大小根据 UILabel 宽度变化
<p><p>我已经用这种方式创建了一个<code>NSAttributedString</code></p>
<pre><code>attribute3=[
NSForegroundColorAttributeName: innercircleColor,
NSFontAttributeName:UIFont.init(name: "Bariol", size: 18.0)!]
attriType=NSAttributedString.init(string: type, attributes: attribute3)
lblType.setAttributedText(attriType)
</code></pre>
<p>但根据我的 <code>UILabel</code> 大小,在 iPhone 5s 中,此属性文本位于 UILabel 之外。如何使属性文本字体大小适合 <code>UILabel</code> 宽度</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您想要的是 <code>UILabel</code> 上的 <code>adjustsFontSizeToFitWidth</code> 属性。它会自动调整 <code>Font</code> 的大小以适合框架。 </p>
<p>您还可以使用 <code>numberOfLines</code> 属性设置用于设置文本的行数,还可以使用 <code>minimumFontSize</code> 属性设置字体应缩放到的最小大小。 </p>
<p> <a href="https://developer.apple.com/documentation/uikit/uilabel/1620546-adjustsfontsizetofitwidth" rel="noreferrer noopener nofollow">https://developer.apple.com/documentation/uikit/uilabel/1620546-adjustsfontsizetofitwidth</a> </p></p>
<p style="font-size: 20px;">关于ios - NSAttributedText 字体大小根据 UILabel 宽度变化,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/44786007/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/44786007/
</a>
</p>
页:
[1]