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:
This is possible through using the storyboard or programmatically. Storyboard: Change the 'Line Break Mode' to Character Wrap or Word Wrap and use Alt/Option + Enter key to enter a new line in the UIButton's Title field.
Programmatically. To make a multi-line text in UIButton, you insert a new line character ( \n ) wherever you want in button title and set lineBreakMode to byWordWrapping . You can adjust text alignment with . textAlignment .
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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With