I want to display some text in a label.
The label has a fixed size but the text can vary from one single word to a complete sentence.
Is there a way to automatically resize the text in such a way that it is alway displayed in the largest possible font-size without truncating it?
I'm working through tutorials for days now, but can only find ways to adjust the label size, not the text size.
Here's the step that work in mine: Set width constraint to the label, then click the constraint. Select Size Inspector. Set the relation to less than or equal, and set max width.
To give a dynamic height to an UIlabel in swift we can use the frame property of UILabel. We can create a frame using the CGRect which allows us to give different variables like x position, y position, width, and height. Let's create a label and add it as a subview to our view.
Set minimumScaleFactor
property of UILabel
.
You can change the font size to fit the width of the UILabel (non-multiline):
myLabel.adjustsFontSizeToFitWidth = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With