How to make UILabel automatic text in a storyboard (or interface builder), not programmatically

Every time I click and drag a UILabel into a storyboard and then add text to a text box, the text is cropped, so I need to click and drag the UILabel to stretch it big enough so that the text appears.

I cannot figure out how to make UILabel automatically grow large enough to fit the text.

This will save time when developing new views.

+43
ios iphone xcode interface-builder xcode-storyboard
Jun 14 '13 at 14:55
source share
4 answers

In any element in Interface Builder, you can select an element and click ...

Editor> Size for content (keyboard shortcut: CMD + = )

This will make "sizeToFit" for the selected item. Labels will correspond to their text size, the image will resize the image, etc.

+86
Jun 14 '13 at 2:59
source share

In Xcode 6.1, I had to set the compression priority of the content to a higher value, probably because I had other restrictions that conflicted, or you turned off the sizeToFit parameter.

Content Compression Resistance Priority Before: Before After: After

+29
Nov 18 '14 at 16:14
source share

Make sure the UILabel line settings are set to 0

enter image description here

0
Sep 11 '17 at 16:24
source share

Starting with iOS 6, there is a new API available in Interface Builder, also called Auto Layout. You can specify some shortcomings, and UIKit will resize / move your views based on these limitations. If you do not want to use Autolayout, you can use the autoresizeMask UIViews property (which is also configured in Interface Builder).

Check out the Auto Detect Guide !

To resize views in Interface Builder as they are created, see @Fogmeister answer

-3
Jun 14 '13 at 2:59
source share



All Articles