pilcrowpipe
pilcrowpipe

Reputation: 2658

Prevent UIButton automatic resize after changing text in Interface Builder

If I slightly modify the title text of a UIButton I've added to my view in Interface Builder it automatically resizes the button. This is really annoying if I only make a small change yet have to constantly resize my buttons. Does anybody know of a what to stop this from happening?

Upvotes: 0

Views: 2889

Answers (2)

pilcrowpipe
pilcrowpipe

Reputation: 2658

I'll answer my own question. Instead of directly editing the text inside the label, do so by changing the text in the Title field inside the Attribute Inspector (select the UIBUtton label, then open the inspector tab which is the 3rd icon from the right on the right-hand panel of IB).

Upvotes: 1

user529758
user529758

Reputation:

You can avoid this by assigning a constant-sized frame to your button programmatically. Make sure your button is already created from the XIB/NIB file (i. e. it is not nil and it won't be touched anymore by the NIB/XIB) at a point in the code, then add this line:

myButton.frame = CGRectMake(x, y, width, height);

where x, y, width and height are the desired/expected position and size of the button, respectively.

Upvotes: 1

Related Questions