[英]NSAttributedText font size changes according to the UILabel width
I have created a NSAttributedString
in this way 我以这种方式创建了
NSAttributedString
attribute3=[
NSForegroundColorAttributeName: innercircleColor,
NSFontAttributeName:UIFont.init(name: "Bariol", size: 18.0)!]
attriType=NSAttributedString.init(string: type, attributes: attribute3)
lblType.setAttributedText(attriType)
But according to my UILabel
size, in iPhone 5s this attributed text is coming outside the UILabel. 但是根据我的
UILabel
大小,在iPhone 5s中,此属性文本超出了UILabel。 How can I make the attributed text font size fit to the UILabel
width 如何使属性文本字体大小适合
UILabel
宽度
What you want is the adjustsFontSizeToFitWidth
property on the UILabel
. 您需要的是
UILabel
上的adjustsFontSizeToFitWidth
属性。 It will auto size the Font
to fit the frame. 它将自动调整
Font
大小以适合框架。
You can also set the number of lines to use to set the text using the numberOfLines
property and also the minimum size the font should scale to using the minimumFontSize
property. 您还可以使用
numberOfLines
属性设置用于设置文本的行数,还可以使用minimumFontSize
属性设置字体应缩放到的最小尺寸。
https://developer.apple.com/documentation/uikit/uilabel/1620546-adjustsfontsizetofitwidth https://developer.apple.com/documentation/uikit/uilabel/1620546-adjustsfontsizetofitwidth
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.