Andrey
Andrey

Reputation: 2729

UILabel sizeWithFont on AutoLayout not working

I updating my application, to work with iPhone 6. But, when I switched on autolayout on XIB, label still not resizing.

CGSize expected = [[textLabel text] sizeWithFont:textLabel.font constrainedToSize:max lineBreakMode:textLabel.lineBreakMode];

How can I solve this?

Upvotes: 1

Views: 297

Answers (1)

Zev Eisenberg
Zev Eisenberg

Reputation: 8148

Are you using the size returned from -sizeWithFont:constrainedToSize:lineBreakMode: to set the frame of your label? When using autolayout, you shouldn’t set the frame directly. You will need to update the view’s constraints with the new size.

Note that autolayout is not required for iOS 6. If you don’t have a compelling reason to switch, you may be better off leaving your existing app as-is.

Upvotes: 1

Related Questions