2

I have created a NSAttributedString in this way

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. How can I make the attributed text font size fit to the UILabel width

user1960169
  • 3,533
  • 12
  • 39
  • 61
  • https://stackoverflow.com/questions/21290234/nsattributedstring-ignores-autoshrink-and-numberoflines-for-uilabel-ios-6 ? – Larme Jun 27 '17 at 17:53

1 Answers1

-1

What you want is the adjustsFontSizeToFitWidth property on the UILabel. It will auto size the Font to fit the frame.

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.

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

Harry Singh
  • 826
  • 5
  • 11
  • 1
    I'm not sure haven't tested with attributed text. It should. Otherwise why not just set the font property directly on the UILabel since font size is now handled automatically? – Harry Singh Jun 28 '17 at 08:38