Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I resize a UIButton to fit the text without it going wider than the screen?

I have a UIButton that I want to resize to fit whatever text is inside it. It has a set width of 280, but the text should wrap to the next line(s) and extend the height of the button as needed.

I've set line breaks to Word Wrap and tried sizeToFit but that only makes the button go wider, not vertical.

like image 856
TigerCoding Avatar asked Feb 10 '11 17:02

TigerCoding


1 Answers

Make sure you set the text on your button this way:

[myButton setTitle:@"my title" forState:UIControlStateNormal];

... and [myButton sizeToFit] should work like a charm.

like image 135
Stephane JAIS Avatar answered Oct 10 '22 04:10

Stephane JAIS