Center Multi-Line Text on UIButton using IB

sdknewbie picture sdknewbie · Jan 27, 2012 · Viewed 15.9k times · Source

How do you center text line-by-line in a UIButton using Interface Builder? I am scouring the options and just don't see it. Here's the button:

button with text not centered

Answer

rob mayoff picture rob mayoff · Jan 27, 2012

You can't set the text to be centered in your nib. But you can change the alignment in your code:

- (void)viewDidLoad {
    [super viewDidLoad];

    self.myButton.titleLabel.textAlignment = UITextAlignmentCenter;
}