iphoneiosinterface-buildermultiline

Center Multi-Line Text on UIButton using IB


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


Solution

  • 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 = NSTextAlignmentCenter;
    }