how to make UILabel autosize text in storyboard (or interface builder), NOT programmatically

IphoneIosXcodeInterface BuilderXcode Storyboard

Iphone Problem Overview


Every time I click-and-drag a UILabel to storyboard, and then add text to Text field, the text is cut off, so I then have to click-and-drag the UILabel to stretch it big enough so that the text appears.

I can't figure out how to make the UILabel automatically get big enough to fit the text.

This would save time while designing new views.

Iphone Solutions


Solution 1 - Iphone

On any element in Interface Builder you can select the element and hit...

Editor > Size to Fit Content (keyboard shortcut: CMD+=)

This will do a "sizeToFit" on the selected element. Labels will fit their text size, image view will resize to the image size, etc...

Solution 2 - Iphone

In Xcode 6.1, I had to set Content Compression Resistance Priority to a higher value, likely because I have other constraints that were conflicting, or causing the sizeToFit option to be disabled.

![Content Compression Resistance Priority][1] [1]: http://i.stack.imgur.com/VUrao.png

Before: ![Before][2] [2]: http://i.stack.imgur.com/LYlJf.png

After: ![After][3] [3]: http://i.stack.imgur.com/Nam1X.png

Solution 3 - Iphone

For the text label:

Set Lines to 0

Set Height to Greater than or equal to 30 (or other value)

Now the height will be adjusted based on the lines number.

Solution 4 - Iphone

Starting with iOS 6, there's a new API, available in Interface Builder as well called 'Auto Layout'. You can specify some contraints and UIKit will resize / move your views based on those contraints. If you don't want to use Autolayout you can use the autoresizeMask property of UIViews (which is settable in Interface Builder as well).

Check out the Autolayout Guide!

To resize the views in Interface Builder as you build them, see the reply from @Fogmeister

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDoug NullView Question on Stackoverflow
Solution 1 - IphoneFogmeisterView Answer on Stackoverflow
Solution 2 - IphoneShiprackView Answer on Stackoverflow
Solution 3 - IphoneDan AlboteanuView Answer on Stackoverflow
Solution 4 - IphoneGianluca TranchedoneView Answer on Stackoverflow