Reputation: 7766
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 ?
Upvotes: 2
Views: 4691
Reputation: 1262
In iOS 9 with Swift :
myButton.titleLabel.textAlignment = NSTextAlignment.Center
Upvotes: 0
Reputation: 4061
Now (iOS 6):
myButton.titleLabel.textAlignment = NSTextAlignmentCenter;
change from UI
to NS
Upvotes: 0
Reputation: 38475
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?
Upvotes: 6
Reputation: 6805
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.
Upvotes: -1