NSAttributedText字体大小根据UILabel宽度而变化

时间:2017-06-27 17:02:59

标签: ios swift3 uilabel nsattributedstring

我以这种方式创建了NSAttributedString

attribute3=[
          NSForegroundColorAttributeName: innercircleColor,
          NSFontAttributeName:UIFont.init(name: "Bariol", size: 18.0)!]

attriType=NSAttributedString.init(string: type, attributes: attribute3)
lblType.setAttributedText(attriType)

但根据我的UILabel大小,在iPhone 5s中,这个归属文本不在UILabel之内。如何使属性文本字体大小适合UILabel宽度

1 个答案:

答案 0 :(得分:0)

您想要的是adjustsFontSizeToFitWidth上的UILabel属性。它会自动调整Font的大小以适合框架。

您还可以使用numberOfLines属性设置用于设置文本的行数,以及字体应使用minimumFontSize属性缩放的最小大小。

https://developer.apple.com/documentation/uikit/uilabel/1620546-adjustsfontsizetofitwidth

相关问题