0

I have a UILabelthat grows according to the screen size (Using auto resizing). However, the font isn't upscaling. I tried setting the label's adjustFontSizeToFitWidth property to YES, but it isn't working. Here is my code.

 override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        outLabel.numberOfLines = 1
        outLabel.adjustsFontSizeToFitWidth = true
        outLabel.textAlignment = NSTextAlignment.center  
    }

I am not sure what to do at all. The font size stays the same no matter what.

Curt Rand
  • 1,025
  • 1
  • 9
  • 27
  • is it growing vertically as well as horizontally ? – Woodstock Dec 11 '18 at 13:55
  • Yes., the label growing both horizontally and vertically using auto resizing. – Curt Rand Dec 11 '18 at 13:56
  • The font isn't supposed to update based on the label size. Maybe setting a large initial font size would work with `adjustsFontSizeToFitWidth`, otherwise update the font in layoutSubviews based on the frame. – James P Dec 11 '18 at 14:46

1 Answers1

0

I implemented something similar to this and the way I solved the problem is by setting the font size at a high number to begin with. adjustsFontSizeToFitWidth should work to downscale your font size according to the width.

For example, set font size at 20 and adjustsFontSizeToFitWidth will downscale the font size to fit current UILabel width.

I hope this helps.

DevKyle
  • 1,091
  • 6
  • 22