I'm creating a xib using autolayout (NSLayoutConsraint). Is there a way to use sizeToFit or something similar to make a UILabel fit its contents?
I've tried setting a constraint of "greater than or equal to x" and tried setting the height to be below this. However, it keeps overwriting the height property. sitToFit doesn't seem to work when you have NSLayoutConstraints.
How can I get the label to size appropriately?
The multiplier which is represented as M in the equation is use to multiply (adjust) the relation by a certain of floating point value. We can say viewA. height should be *2 (two times) of viewB.
To summarize, you can calculate the height of a label by using its string and calling boundingRectWithSize . You must provide the font as an attribute, and include . usesLineFragmentOrigin for multi-line labels.
Auto layout is a property you can add to frames and components. It lets you create designs that grow to fill or shrink to fit, and reflow as their contents change. This is great when you need to add new layers, accommodate longer text strings, or maintain alignment as your designs evolve.
A view that displays one or more lines of informational text.
Make an IBOutlet for your width and height constraints, and use sizeToFit
to change their constant
property, and call needsUpdateConstraints
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