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



我以这种方式创建了一个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宽度

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

您还可以设置用于使用numberOfLines属性设置文本的行数,以及该字体应扩展为使用minimumFontSize属性的最小尺寸。

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

最新更新