0
votes

I'm having trouble having text fit in my UILabel using iOS 10 if the text exceeds the size of the width/height constraints of my label.

This is the size inspector in the Storyboard for the UILabel:

enter image description here

I want to UILabel itself to always have a fixed width and height as it currently has in the Storyboard. I just want the text to word wrap/change font size and do whatever it has to, to fit the confines of that width/height specification. I've tried the following on the UILabel:

adjustsFontSizeToFitWidth
numberOfLines = 0

I can't seem to get the right configuration.

1
It sounds like you've tried the right thing - adjustsFontSizeToWidth - but maybe if you included your code something might stick out. Also, check that you have the IBOutlet created correctly.dfd

1 Answers

3
votes

You must set minimumScaleFactor less than 1 and numberOfLines to 1 or greater for adjustsFontSizeToFitWidth to have an effect.

 

Swift Code

label.numberOfLines = 1
label.adjustsFontSizeToFitWidth = true
label.minimumScaleFactor = 0.5

 

Interface Builder

enter image description here