Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 884
sdknewbie Avatar asked Jan 27 '12 14:01

sdknewbie


People also ask

How to make button title multiline swift?

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.

How do I add text to UIButton?

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 .


1 Answers

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; } 
like image 195
rob mayoff Avatar answered Sep 18 '22 13:09

rob mayoff