I have a square UILabel
(in yellow color) which contains a single letter.
I have used the following code from this SO answer to adjust the font size such that it fits into the UILabel
:
letterLabel.font = UIFont(name: letterLabel.font.fontName, size: 100)
letterLabel.adjustsFontSizeToFitWidth = true
letterLabel.textAlignment = NSTextAlignment.Center
As apparent in the screenshot, the font size is according to the width. But since the text is only one letter, hence we also need to look at the height. How can we adjust the font size such that height is also within the UILabel
?
letterLabel.sizeToFit()
– b26