views:

60

answers:

2

I change the text of one of my buttons, I didn't realize that the text wasn't centered.

Its set in IB

How do I center it ?

+5  A: 

It's just a text label so this should work (put it in your viewDidLoad method and set myButton as an IBOutlet property)

myButton.titleLabel.textAlignment = UITextAlignmentCenter;

However, it should already be centered - it seems odd that it isn't. Are you doing anything else unusual?

deanWombourne
Don't they default to left alignment?
jrtc27
Not in the UIButton I just created in Interface builder it didn't :) However, the answer from Josh Hinman might shed some lght on the matter.
deanWombourne
A: 

In Interface Builder, select the button and press ⌘-1 to bring up the attributes inspector. Look towards the bottom of the attributes, under "Control". You will see something that says "Content" with alignment buttons. Press the button for center alignment.

Josh Hinman