Multiline Button Text

The button’s titleLabel property allows you to modify title attributes such as its font and line break mode. Here, the font is set to a very large value (basically ensuring that the text needs to wrap to display correctly) and used with word wrap and centered alignment:

button.titleLabel.font = [UIFont boldSystemFontOfSize:36.0f]; [button setTitle:@"Lorem Ipsum Dolor Sit" forState:     UIControlStateNormal]; button.titleLabel.textAlignment = UITextAlignmentCenter; button.titleLabel.lineBreakMode = UILineBreakModeWordWrap;

By default, button labels stretch from one end of your button to the other. This means that text may extend farther out than you might otherwise want, possibly beyond the edges ...

Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.