How do you add multi-line text to a UIButton? How do you add multi-line text to a UIButton? ios ios

How do you add multi-line text to a UIButton?


For iOS 6 and above, use the following to allow multiple lines:

button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;// you probably want to center itbutton.titleLabel.textAlignment = NSTextAlignmentCenter; // if you want to [button setTitle: @"Line1\nLine2" forState: UIControlStateNormal];

For iOS 5 and below use the following to allow multiple lines:

button.titleLabel.lineBreakMode = UILineBreakModeWordWrap;// you probably want to center itbutton.titleLabel.textAlignment = UITextAlignmentCenter;[button setTitle: @"Line1\nLine2" forState: UIControlStateNormal];

2017, for iOS9 forward,

generally, just do these two things:

  1. choose "Attributed Text"
  2. on the "Line Break" popup select "Word Wrap"


The selected answer is correct but if you prefer to do this sort of thing in Interface Builder you can do this:

pic


If you want to add a button with the title centered with multiple lines, set your Interface Builder's settings for the button:

[here]